DataGridView.HitTestInfo.ColumnIndex 속성

정의

현재 DataGridView.HitTestInfo에서 설명하는 좌표가 포함된 열의 인덱스를 가져옵니다.

public:
 property int ColumnIndex { int get(); };
public int ColumnIndex { get; }
member this.ColumnIndex : int
Public ReadOnly Property ColumnIndex As Integer

속성 값

Int32

현재 DataGridView에서 설명하는 좌표가 포함된 DataGridView.HitTestInfo 열의 인덱스입니다.

예제

다음 코드 예제에서는이 속성의 사용을 보여 줍니다. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 DataGridView.Columns 속성 참조 항목입니다.

private DataGridViewCell clickedCell;

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// If the user right-clicks a cell, store it for use by the shortcut menu.
    if (e.Button == MouseButtons.Right)
    {
        DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
        if (hit.Type == DataGridViewHitTestType.Cell)
        {
            clickedCell =
                dataGridView1.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
        }
    }
}
Private clickedCell As DataGridViewCell

Private Sub dataGridView1_MouseDown(ByVal sender As Object, _
    ByVal e As MouseEventArgs) Handles dataGridView1.MouseDown

    ' If the user right-clicks a cell, store it for use by the 
    ' shortcut menu.
    If e.Button = MouseButtons.Right Then
        Dim hit As DataGridView.HitTestInfo = _
            dataGridView1.HitTest(e.X, e.Y)
        If hit.Type = DataGridViewHitTestType.Cell Then
            clickedCell = _
                dataGridView1.Rows(hit.RowIndex).Cells(hit.ColumnIndex)
        End If
    End If

End Sub

적용 대상

추가 정보