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";
Me.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";
}
}
Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
If (e.CellElement.RowIndex Mod 2 = 0) Then
e.CellElement.RowInfo.Tag = "Some tag"
Else
e.CellElement.RowInfo.Tag = "Hide row"
End If
End Sub
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;
}
}
Private Sub RadGridView1_CellFormatting1(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
If TypeOf e.CellElement.RowInfo.Tag Is [String] AndAlso DirectCast(e.CellElement.RowInfo.Tag, String) = "Hide row" Then
e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
End If
End Sub
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.