双击DataGridView行? [英] Double-click DataGridView row?

查看:316
本文介绍了双击DataGridView行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在winform上使用vb.net和DataGridView。



当用户双击一行时,我想对此行执行某些操作。但是我怎么知道用户是单击一行还是在网格中的任何地方?如果我使用 DataGridView.CurrentRow ,那么如果一个行被选中并且用户在网格上的任何位置单击,当前行将显示所选择的,而不是用户点击的位置(在这种情况下)不会在一行,我想忽略它)。

解决方案

尝试 CellMouseDoubleClick 事件...



  Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)处理DataGridView1.CellMouseDoubleClick 
如果e.RowIndex> = 0 AndAlso e.ColumnIndex> = 0然后
Dim selectedRow = DataGridView1.Rows(e.RowIndex)
End If
End Sub

只有用户实际上在网格中的单元格时才会触发。 如果检查过滤掉行选择器和标题的双击。


I am using vb.net and DataGridView on a winform.

When a user double-clicks on a row I want to do something with this row. But how can I know whether user clicked on a row or just anywhere in the grid? If I use DataGridView.CurrentRow then if a row is selected and user clicked anywhere on the grid the current row will show the selected and not where the user clicked (which in this case would be not on a row and I would want to ignore it).

解决方案

Try the CellMouseDoubleClick event...

Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
    If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
        Dim selectedRow = DataGridView1.Rows(e.RowIndex)
    End If
End Sub

This will only fire if the user is actually over a cell in the grid. The If check filters out double clicks on the row selectors and headers.

这篇关于双击DataGridView行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆