为控件创建自定义定义/属性

时间:2015-08-17 09:35:33

标签: c# .net

我目前正要设计一个使用DataGridView的项目。作为其中一个事件,我希望它在双击一行时执行任务。

环顾四周,我可以找到创建自己的事件的示例,但是我注意到DataGridView没有双击行的属性或定义,并且想知道我如何自己指定它?

1 个答案:

答案 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
    ...
}