DataGridViewCellFormattingEventArgs::RowIndex Property

 

Gets the row index of the cell that is being formatted.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property int RowIndex {
	int get();
}

Property Value

Type: System::Int32

The row index of the cell that is being formatted.

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
Return to top
Show: