Double-click DataGridView row?

时光毁灭记忆、已成空白 提交于 2019-11-30 13:01:19

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.

Use Datagridview DoubleClick Evenet and then Datagrdiview1.selectedrows[0].cell["CellName"] to get value and process.

Below example shows clients record upon double click on selected row.

private void dgvClientsUsage_DoubleClick(object sender, EventArgs e) {

        if (dgvClientsUsage.SelectedRows.Count < 1)
        {
            MessageBox.Show("Please select a client");
            return;
        }

        else
        {
            string clientName = dgvClientsUsage.SelectedRows[0].Cells["ClientName"].Value.ToString();

            // show selected client Details
            ClientDetails clients = new ClientDetails(clientName);
            clients.ShowDialog();

        }
    }

Use DataGridView.HitTest in the double-click handler to find out where the click happened.

I would use the DoubleClick event of the DataGridView. This will at least only fire when the user double clicks in the data grid - you can use the MousePosition to determine what row (if any) the user double clicked on.

You could try something like this.

Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
    For index As Integer = 0 To DataGridView1.Rows.Count
        If DataGridView1.Rows(index).Selected = True Then
            'it is selected
        Else
            'is is not selected
        End If
    Next
End Sub

Keep in mind i could not test this because i diddent have any data to populate my DataGridView.

Sudharsan

You can try this:

Private Sub grdview_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdview.CellDoubleClick

    For index As Integer = 0 To grdview.Rows.Count - 1

        If e.RowIndex = index AndAlso e.ColumnIndex = 1 AndAlso grdview.Rows(index).Cells(1).Value = "" Then

            MsgBox("Double Click Message")

        End If
    Next
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!