DataGridViewCellValueEventArgs::ColumnIndex Property
.NET Framework (current version)
Gets a value indicating the column index of the cell that the event occurs for.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System::Int32The index of the column containing the cell that the event occurs for.
The following code example demonstrates how to use the ColumnIndex property to retrieve cell values from the data store. 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; } }
.NET Framework
Available since 2.0
Available since 2.0
Show: