无法在datagridview中打开浏览

时间:2011-10-05 09:05:09

标签: c# datagridview openfiledialog

我有一个DataGridView,如图所示,当我点击“从文件浏览”时,OpenFileDialog必须打开。我相信如果我在button_Click方法下编写代码,就没有办法成为可能,但我不知道在哪种方法下编写我的代码。请帮忙。

enter image description here

就目前而言,我已经做到了这一点:(希望有所帮助)

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;
                }
            }

1 个答案:

答案 0 :(得分:1)

将您的代码放入DataGridView.CellValueChanged事件中。使用SelectedCells属性查找当前单元格,然后检查其值是否为“Browse From File ...”。如果是,请点按OpenFileDialog.ShowDialog()来电。

请参阅此文档了解CellValueChanged:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx

相关问题