我在datagridview控件中有4列,其中第二列是datagridviewtext列,而第三列是第4列是datagridviewbutton列。 如何为datagridviewbutton单击以及datagridviewtext列的不同事件触发不同事件,因为它在datagirdview cellcontent单击中都会出现。 或者在datagridview单元格内容中单击按钮或文本的任何其他方式单击。
答案 0 :(得分:1)
在CellContentClick
事件中,一种方法是检查单元格类型,如下所示:
if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewButtonCell)
{
// handle button cell click
}
else if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewTextBoxCell)
{
// handle textbox cell click
}
其他细胞类型也一样。