DataGridViewCellFormattingEventArgs::RowIndex Property
.NET Framework (current version)
Gets the row index of the cell that is being formatted.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Use the RowIndex property to obtain an index into the Rows property of a DataGridView.
The following code example demonstrates how to use the RowIndex property to retrieve the cell being formatted. The cell reference is then used to set the cell's ToolTip text.
// Sets the ToolTip text for cells in the Rating column. void dataGridView1_CellFormatting(Object^ /*sender*/, DataGridViewCellFormattingEventArgs^ e) { if ( (e->ColumnIndex == this->dataGridView1->Columns["Rating"]->Index) && e->Value != nullptr ) { DataGridViewCell^ cell = this->dataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex]; if (e->Value->Equals("*")) { cell->ToolTipText = "very bad"; } else if (e->Value->Equals("**")) { cell->ToolTipText = "bad"; } else if (e->Value->Equals("***")) { cell->ToolTipText = "good"; } else if (e->Value->Equals("****")) { cell->ToolTipText = "very good"; } } }
.NET Framework
Available since 2.0
Available since 2.0
Show: