C# 对于';突出显示行号';

C# 对于';突出显示行号';,c#,C#,我已经填充了一个datagrid,但希望在用户双击该行并高亮显示该行时触发一个事件。我看了所有的财产,但似乎不知道是哪一个 我也看过MSDN,但也看不到任何东西 非常感谢, Sam尝试使用下面的代码: this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick); private void dataGr

我已经填充了一个datagrid,但希望在用户双击该行并高亮显示该行时触发一个事件。我看了所有的财产,但似乎不知道是哪一个

我也看过MSDN,但也看不到任何东西

非常感谢,


Sam尝试使用下面的代码:

this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick);

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{

}

尝试使用以下代码:

this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick);

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{

}

CellDoubleClick
的问题在于,当键盘用户使用箭头导航时,它不会触发事件

相反,您可以处理的其他一些事件是:

通过将处理程序附加到每个事件并写入“输出”窗口,可以在每个事件触发时四处查看:

dataGridView1.rownenter+=dgv_rownenter;
dataGridView1.SelectionChanged+=dgv_SelectionChanged;
dataGridView1.RowStateChanged+=dgv_RowStateChanged;
dataGridView1.CellContentClick+=dgv_CellContentClick;
私有void dgv_RowEnter(对象发送方,DataGridViewCellEventArgs e)
{
Debug.WriteLine(“rownenter”);
}
私有无效dgv_SelectionChanged(对象发送方,事件参数e)
{
Debug.WriteLine(“SelectionChanged”);
}
私有void dgv_RowStateChanged(对象发送方,DataGridViewRowStateChangedEventArgs e)
{
Debug.WriteLine(“RowStateChanged”);
}
私有void dgv_CellContentClick(对象发送方,DataGridViewCellEventArgs e)
{
Debug.WriteLine(“CellContentClick”);
}

CellDoubleClick的问题在于,当键盘用户使用箭头导航时,它不会触发事件

相反,您可以处理的其他一些事件是:

通过将处理程序附加到每个事件并写入“输出”窗口,可以在每个事件触发时四处查看:

dataGridView1.rownenter+=dgv_rownenter;
dataGridView1.SelectionChanged+=dgv_SelectionChanged;
dataGridView1.RowStateChanged+=dgv_RowStateChanged;
dataGridView1.CellContentClick+=dgv_CellContentClick;
私有void dgv_RowEnter(对象发送方,DataGridViewCellEventArgs e)
{
Debug.WriteLine(“rownenter”);
}
私有无效dgv_SelectionChanged(对象发送方,事件参数e)
{
Debug.WriteLine(“SelectionChanged”);
}
私有void dgv_RowStateChanged(对象发送方,DataGridViewRowStateChangedEventArgs e)
{
Debug.WriteLine(“RowStateChanged”);
}
私有void dgv_CellContentClick(对象发送方,DataGridViewCellEventArgs e)
{
Debug.WriteLine(“CellContentClick”);
}

不确定“rownumber”的实际含义,但您可以编写一个事件来检查现在选择了哪些行(如果有的话)。。注意我尝试过的方法,但它是在单元格的基础上进行的,并且在填充datagrid时也会触发。另外,我想它的双击选项,而不是单一的。我已经修改了我的问题。@taw我认为行高亮显示的事件将是相当标准的…您还可以对
RowStateChanged
事件进行编码,并测试
DataGridViewElementState的新状态。已选择
。但您还需要几个附加条件,请记住双击和一些有关行数的有趣内容。不确定“行数”的实际含义,但您可以编写一个事件来检查现在选择了哪些行(如果有的话)。。注意我尝试过的方法,但它是在单元格的基础上进行的,并且在填充datagrid时也会触发。另外,我想它的双击选项,而不是单一的。我已经修改了我的问题。@taw我认为行高亮显示的事件将是相当标准的…您还可以对
RowStateChanged
事件进行编码,并测试
DataGridViewElementState的新状态。已选择
。但您还需要一些附加条件,请记住双击和一些有关行号的有趣内容。谢谢。正是我需要的。我会在6分钟内记下答案。谢谢。正是我需要的。我会在6分钟内记下答案。谢谢。现在不需要,但很有帮助。谢谢。现在不需要,但有帮助。