1 回答
TA贡献1821条经验 获得超4个赞
最后一行的断点(来自评论):当然,这不能解决问题,但现在您知道它本身DataTable
是错误的。现在使用断点继续执行代码。您可以将其设置在线上DataTable dt = new DataTable();
并查看上面的行,当将鼠标悬停在 上方时ofdialog
,查看它的文件集合FileNames
。
OpenFileDialog1.Multiselect = True您应该获得的文件数量等于您在OpenFileDialog.
下一个候选是filename带有断点的数组foreach,检查该数组中的项目数。
这是我用来比较的代码:
C#(转换后):
OpenFileDialogDXF.Title = "Choose your files";
OpenFileDialogDXF.InitialDirectory = @"C:\users\XXXXX\Documents\";
OpenFileDialogDXF.Filter = "DXF Files|*.dxf";
OpenFileDialogDXF.Multiselect = true;
if (OpenFileDialogDXF.ShowDialog() == DialogResult.OK)
{
for (var ir = 0; ir <= OpenFileDialogDXF.FileNames.Count - 1; ir++)
LoadDXF(OpenFileDialogDXF.FileNames(ir));
}
VB.NET:
Private Sub BtnOpenDxf_Click(sender As Object, e As EventArgs) Handles BtnOpenDxf.Click
OpenFileDialogDXF.Title = "Choose your files"
OpenFileDialogDXF.InitialDirectory = "C:\users\XXXXX\Documents\"
OpenFileDialogDXF.Filter = "DXF Files|*.dxf"
OpenFileDialogDXF.Multiselect = True
If OpenFileDialogDXF.ShowDialog() = DialogResult.OK Then
For ir = 0 To OpenFileDialogDXF.FileNames.Count - 1
Call LoadDXF(OpenFileDialogDXF.FileNames(ir))
Next
End If
我的自定义子程序在哪里LoadDXF处理每个文件。
编辑:
考虑一下您的代码,如果OpenFileDialog获得多个结果,我要查找问题的地方就是这一行:
string[] filename = ofdialog.FileNames;
它可能需要一些转换,例如.ToArray().
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报