DataGridView Control에서 오른쪽 마우스 버튼 사용 하기

2010. 5. 1. 11:17

Private Sub DataGridView_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView.MouseUp

If e.Button = MouseButtons.Right Then
    Dim hti As DataGridView.HitTestInfo = sender.HitTest(e.X, e.Y)
        If hti.Type = DataGridViewHitTestType.Cell Then
            If Not DataGridView.Rows(hti.RowIndex).Selected Then
                ' User right clicked a row that is not selected, so throw away all other selections and select this row
                DataGridView.ClearSelection()
                DataGridView.Item(1, hti.RowIndex).Selected = True '해당 마우스 좌표의 셀 선택
            End If
        End If
End If

End Sub

행 선택하기

Me.DataGridView.Rows(RowIndex).Selected = True

Binple 개발/Visual Basic , ,