即使我们单击DataGridView的标题,单元格单击事件也会被触发。如何阻止它开火?
答案 0 :(得分:3)
比较RowIndex
和ColIndex
,如果它们的值为-1(标题列/行索引),则为ignore
。
testDataGridView.CellClick += (senderObject, eventArgs) =>
{
if (eventArgs.RowIndex == -1 || eventArgs.ColumnIndex == -1)
return;
//statements here
};
答案 1 :(得分:1)
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
{
return;
}
//Write your code here ...
}