Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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.CellContentClick中出错_C#_Datagridview - Fatal编程技术网

C# DataGridview.CellContentClick中出错

C# DataGridview.CellContentClick中出错,c#,datagridview,C#,Datagridview,我正在处理单元格内容单击事件。 当用户单击单元格内容时,它会准确捕获 考虑这种情况,在第3列中有DataGridViewLinkColumn 但在单击单元格(如第1行第3列)后,当用户意外单击任何一个表头时,cellclick事件将保留,即它使用相同的RowIndex和ColumnIndex(第1行和第3列)调用CellContentClicked事件 如何避免这种情况? 请帮助..这基本上是因为最后一行/默认选中的行。若要解决此问题,可以将默认选择属性设置为“无”来定义控件 与listview

我正在处理单元格内容单击事件。 当用户单击单元格内容时,它会准确捕获

考虑这种情况,在第3列中有DataGridViewLinkColumn 但在单击单元格(如第1行第3列)后,当用户意外单击任何一个表头时,cellclick事件将保留,即它使用相同的RowIndex和ColumnIndex(第1行和第3列)调用CellContentClicked事件

如何避免这种情况?
请帮助..

这基本上是因为最后一行/默认选中的行。若要解决此问题,可以将默认选择属性设置为“无”来定义控件

与listview类似,我使用的是:

<ListView ItemContainerStyle="{StaticResource listViewStyle}" SelectedIndex=-1 .. />

我找到了答案。。 单击表格标题时,将为上一个选定的单元格触发单元格单击

我们可以通过添加条件来限制此功能

如果(e.CoumnIndex>=0&&e.RowIndex>=0)

{

}


(对于标题行,行索引为-1)

对于Windows窗体应用程序

if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{         
    // Add  Logic  for Cell Click event
}
else
{
   MessageBox.Show("Error Message", "My Application",
   MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}

@StanislavStoyanov,我不确定他是在wpf、asp.net还是Win表单中工作。顺便说一句,在windows窗体开发中工作时会有所不同吗?很抱歉,问题不清楚。我在Winforms 4.0中工作
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{         
    // Add  Logic  for Cell Click event
}
else
{
   MessageBox.Show("Error Message", "My Application",
   MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}