我目前正要设计一个使用DataGridView
的项目。作为其中一个事件,我希望它在双击一行时执行任务。
环顾四周,我可以找到创建自己的事件的示例,但是我注意到DataGridView
没有双击行的属性或定义,并且想知道我如何自己指定它?
答案 0 :(得分:3)
有一个CellMouseDoubleClick
事件,与“普通”DataGridView的鼠标双击事件相反,只有当用户实际双击一行的单元格时才会触发。
关于如何自己完成的问题:您可以尝试从DataGridView
派生一个新类,在内部附加CellMouseDoubleClick
事件,然后触发一个新事件,传递单击的行。例如:
private void DataGridView1_CellMouseDoubleClick(Object sender, DataGridViewCellMouseEventArgs e)
{
// Determine the row the clicked cell belongs to
...
// Fire a new event for that row
...
}