我编写了这段代码,用于通过单击按钮向 datagridview 添加多个附件,但我一次只能添加一个附件。单击下一个按钮不会添加多个附件,请提供解决方案,
谢谢
这是我尝试过的代码
OpenFileDialog ofdialog = new OpenFileDialog();
ofdialog.Multiselect = true;
DataTable dt = new DataTable();
dt.Columns.Add("Attachments");
var res = ofdialog.ShowDialog();
string[] filename = ofdialog.FileNames;
string[] sfilename = ofdialog.SafeFileNames;
foreach (string fn in filename)
{
dt.Rows.Add(fn);
}
dataGridView1.DataSource = dt.DefaultView;
dataGridView1.Columns["Attachments"].Width = 500;
收到一只叮咚
相关分类