Skip to main content
 首页 » 编程设计

c#之DataGridView 的 CellClick 事件

2024年02月23日15qq78292959

即使我们单击 DataGridView 的标题,单元格单击事件也会被触发。如何阻止它发射?

请您参考如下方法:

比较 RowIndex 和 ColIndex,如果它们的值为 -1(标题列/行索引),则忽略。

testDataGridView.CellClick += (senderObject, eventArgs) => 
 { 
  if (eventArgs.RowIndex == -1 || eventArgs.ColumnIndex == -1) 
    return; 
  //statements here 
 };