Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGridView的CellClick事件_C#_Winforms - Fatal编程技术网

C# DataGridView的CellClick事件

C# DataGridView的CellClick事件,c#,winforms,C#,Winforms,即使单击DataGridView的标题,也会触发单元格单击事件。如何阻止它触发?比较行索引和ColIndex如果它们有-1(标题列/行索引)值,则忽略它 testDataGridView.CellClick += (senderObject, eventArgs) => { if (eventArgs.RowIndex == -1 || eventArgs.ColumnIndex == -1) return; //statements here }; 比较RowInd

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

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

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

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

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

IMHO,您应该尝试正确处理事件,而不是在偶然情况下阻止事件的执行。IMHO,您应该尝试正确处理事件,而不是在偶然情况下阻止事件的执行。