无法在 datagridview 中打开浏览
如图所示,我有一个 DataGridView,当我单击“从文件浏览”时,必须打开 OpenFileDialog。我相信如果我在 Button_Click 方法下编写代码,但我不知道在哪种方法下编写代码,则没有办法成为可能。请帮忙。
到目前为止我已经做到了:(希望有帮助)
string[] col2 = new string[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
if (col2[i] == "Browse From File...")
{
DialogResult result2 = openFileDialog2.ShowDialog();
if (result2 == DialogResult.OK)
{
filename = openFileDialog1.FileName;
}
}
I have a DataGridView as seen in the picture and a OpenFileDialog has to open when I click on "Browse from file". I believe there is no way to become possible if i write my code under the button_Click methods but i dont know under which method to write my code. Please help.
As far as now I have made this: (hope it helps)
string[] col2 = new string[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
if (col2[i] == "Browse From File...")
{
DialogResult result2 = openFileDialog2.ShowDialog();
if (result2 == DialogResult.OK)
{
filename = openFileDialog1.FileName;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码放入
DataGridView.CellValueChanged
事件中。使用SelectedCells
属性查找当前单元格,然后检查其值是否为“从文件浏览...”。如果是这样,请关闭OpenFileDialog.ShowDialog()
调用。有关 CellValueChanged,请参阅此文档: http://msdn .microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx
Place your code in the
DataGridView.CellValueChanged
event. Use theSelectedCells
property to find the current cell, then check if its value is "Browse From File...". If so, fire off theOpenFileDialog.ShowDialog()
call.See this documentation for CellValueChanged: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx