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

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

问题描述

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

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

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

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).

推荐答案

尝试 CellMouseDoubleClick 事件...

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

仅当用户实际位于网格中的单元格上方时才会触发.If 检查过滤掉对行选择器和标题的双击.

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天全站免登陆