1
오른쪽 클릭으로 DataGridView에서 행을 선택하고 싶습니다. 그러나 현재 코드를 사용하려면 먼저 마우스 왼쪽 버튼을 클릭하여 행을 클릭해야합니다.DataGridView select 행
오른쪽 클릭으로 현재 행을 선택하고 ContextMenuStrip을 여는 방법이 있습니까?
Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown
If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex >= 0 Then
Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
End If
End Sub
Private Sub datagridview1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim hti As DataGridView.HitTestInfo = sender.HitTest(e.X, e.Y)
If hti.Type = DataGridViewHitTestType.Cell Then
If Not DataGridView1.Rows(hti.RowIndex).Selected Then
DataGridView1.ClearSelection()
DataGridView1.Rows(hti.RowIndex).Selected = True
End If
End If
End If
End Sub
가능한 중복? http://stackoverflow.com/q/5884713/211627 – JDB