New to Telerik UI for WinForms? Download free 30-day trial

Tag property

Each row has a Tag property of type object where you can store a custom object.

Setting the Tag property of a row


this.radGridView1.Rows[1].Tag = "Some tag";

Setting the Tag property of cells in CellFormatting event.

void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.RowIndex % 2 == 0)
    {
        e.CellElement.RowInfo.Tag = "Some tag";
    }
    else
    {
        e.CellElement.RowInfo.Tag = "Hide row";
    }
}

Collapsing all rows with the specified tag

The most natural place to use the tag is in some of the row/cell events. For example, to make the content of certain cells invisible use the following code:

void radGridView1_CellFormatting1(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.RowInfo.Tag is String && (string)e.CellElement.RowInfo.Tag == "Hide row")
    {
        e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    }
}

Cells also have Tag property but it differs substantially from rows one because of the UI Virtualization. Cells are reused and when you scroll the tag value remains unchanged while cell data value is updated.