我在 datagridview 中有一个按钮单元格。单击该按钮时,另一个 datagridview 应该可见。对于按钮列中的每个按钮单击,新 datagridview 中的数据应该有所不同。我不知道如何实现按钮单击事件每行都不同。请帮助我编写示例代码。
您无法为按钮单元格实现按钮单击事件DataGridViewButtonColumn
。相反,您使用 DataGridView 的CellClicked
事件并确定该事件是否为您的单元格触发DataGridViewButtonColumn
。使用事件的DataGridViewCellEventArgs.RowIndex
属性来找出单击了哪一行。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {
// Ignore clicks that are not in our
if (e.ColumnIndex == dataGridView1.Columns["MyButtonColumn"].Index && e.RowIndex >= 0) {
Console.WriteLine("Button on row {0} clicked", e.RowIndex);
}
}
MSDN 文档中关于DataGridViewButtonColumn 类有一个更完整的例子。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)