DataGridViewCellValueEventArgs.ColumnIndex 속성

정의

이벤트가 발생하는 셀의 열 인덱스를 나타내는 값을 가져옵니다.Gets a value indicating the column index of the cell that the event occurs for.

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

속성 값

이벤트가 발생하는 셀이 포함된 열의 인덱스입니다.The index of the column containing the cell that the event occurs for.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ColumnIndex 데이터 저장소에서 셀 값을 검색할 속성입니다.The following code example demonstrates how to use the ColumnIndex property to retrieve cell values from the data store. 이 예제는 다음 방법에 제공 된 더 큰 예제의 일부입니다. Windows Forms DataGridView 컨트롤에서 가상 모드를 구현 합니다.This example is part of a larger example provided in How to: Implement Virtual Mode in the Windows Forms DataGridView Control.

void dataGridView1_CellValueNeeded( Object^ /*sender*/,
    System::Windows::Forms::DataGridViewCellValueEventArgs^ e )
{
   Customer^ customerTmp = nullptr;
   
   // Store a reference to the Customer object for the row being painted.
   if ( e->RowIndex == rowInEdit )
   {
      customerTmp = this->customerInEdit;
   }
   else
   {
      customerTmp = dynamic_cast<Customer^>(this->customers[ e->RowIndex ]);
   }
   
   // Set the cell value to paint using the Customer object retrieved.
   int switchcase = 0;
   if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Company Name" ) )
         switchcase = 1;
   else
   if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Contact Name" ) )
         switchcase = 2;


   switch ( switchcase )
   {
      case 1:
         e->Value = customerTmp->CompanyName;
         break;

      case 2:
         e->Value = customerTmp->ContactName;
         break;
   }
}


private void dataGridView1_CellValueNeeded(object sender,
    System.Windows.Forms.DataGridViewCellValueEventArgs e)
{
    // If this is the row for new records, no values are needed.
    if (e.RowIndex == this.dataGridView1.RowCount - 1) return;

    Customer customerTmp = null;

    // Store a reference to the Customer object for the row being painted.
    if (e.RowIndex == rowInEdit)
    {
        customerTmp = this.customerInEdit;
    }
    else 
    {
        customerTmp = (Customer)this.customers[e.RowIndex];
    }

    // Set the cell value to paint using the Customer object retrieved.
    switch (this.dataGridView1.Columns[e.ColumnIndex].Name)
    {
        case "Company Name":
            e.Value = customerTmp.CompanyName;
            break;

        case "Contact Name":
            e.Value = customerTmp.ContactName;
            break;
    }
}
Private Sub dataGridView1_CellValueNeeded(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellValueEventArgs) _
    Handles dataGridView1.CellValueNeeded

    ' If this is the row for new records, no values are needed.
    If e.RowIndex = Me.dataGridView1.RowCount - 1 Then
        Return
    End If

    Dim customerTmp As Customer = Nothing

    ' Store a reference to the Customer object for the row being painted.
    If e.RowIndex = rowInEdit Then
        customerTmp = Me.customerInEdit
    Else
        customerTmp = CType(Me.customers(e.RowIndex), Customer)
    End If

    ' Set the cell value to paint using the Customer object retrieved.
    Select Case Me.dataGridView1.Columns(e.ColumnIndex).Name
        Case "Company Name"
            e.Value = customerTmp.CompanyName

        Case "Contact Name"
            e.Value = customerTmp.ContactName
    End Select

End Sub

설명

이 오프셋을 사용 하 여는 Columns 속성에 대 한 이벤트가 발생 하는 셀을 참조 합니다.Use this offset with the Columns property to reference the cell that the event occurs for.

적용 대상

추가 정보