不出现打开文件对话框
我有这个 DataGridView,我希望每次单击“从文件浏览...”时打开一个 openFileDialog。
到目前为止已完成,但不起作用。
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
string bbb = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (bbb == "Browse From File...")
{
openFileDialog2.ShowDialog();
}
也尝试过这些,但一无所获:
if (e.ColumnIndex.Equals = "Browse From File...")
if (dataGridView1.SelectedCells = "Browse From File...")
if ((string)dataGridView1.SelectedCells[0].Value == "Browse From File...")
if (dataGridView1.Rows[1].Cells["Browse From File..."].Value.ToString() == "Browse From File...")
{
//openFileDialog2.ShowDialog();
}
I have this DataGridView and I want every time you click on the Browse From File... an openFileDialog to open.
Made this so far but it does not work.
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
string bbb = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (bbb == "Browse From File...")
{
openFileDialog2.ShowDialog();
}
Tried also these but nothing:
if (e.ColumnIndex.Equals = "Browse From File...")
if (dataGridView1.SelectedCells = "Browse From File...")
if ((string)dataGridView1.SelectedCells[0].Value == "Browse From File...")
if (dataGridView1.Rows[1].Cells["Browse From File..."].Value.ToString() == "Browse From File...")
{
//openFileDialog2.ShowDialog();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是它应该的样子吗?
Is it what it's supposed to be?
一种解决方案是捕获显示数据网格中的控件的事件 (EditingControlsShowing) 并在组合框中添加 SelectionChanged 处理程序。
像这样的东西:
编辑
为了将事件处理程序添加到网格中: 转到表单的设计视图并右键单击网格。单击上下文菜单中的属性。在属性窗口中,单击事件按钮(闪电图像)并搜索 EditingControlShowing 条目。双击空白处添加事件处理程序。在后面的页面代码中,您将看到一个与 *dataGridView1_EditingControlShowing* 类似的空方法,在该方法中复制/粘贴上述方法中的代码。除此之外,还将第二个方法 cellComboBox_SelectedIndexChanged 复制/粘贴到同一源文件中。
One solution would be to catch the event where the controls from the datagrid are shown (EditingControlsShowing) and add SelectionChanged handler on the combo box.
Something like this:
Edit
In order to add the event handler to the grid: Go to design view for your form and right click on the grid. Click properties in the context menu. In the properties window click on the Events button (the lightning image) and search the EditingControlShowing entry. Double click the empty space to add the event handler. In the page code behind you'll see an empty method similar with *dataGridView1_EditingControlShowing*, in that method copy/paste the code from the above method. Beside that also copy/paste in the same source file the second method cellComboBox_SelectedIndexChanged.