New to Telerik UI for WinForms? Start a free 30-day trial
Row Numbers in RadVirtualGrid
Updated over 6 months ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2020.1.113 | RadVirtualGrid for WinForms | Desislava Yordanova |
Description
This article shows how to display row numbers in RadVirtualGrid.

Solution
It is necessary to handle the CellFormatting event and show the RowIndex in the row header:
C#
public RadForm1()
{
InitializeComponent();
this.radVirtualGrid1.RowCount = 130;
this.radVirtualGrid1.ColumnCount = 2;
this.radVirtualGrid1.CellValueNeeded += radVirtualGrid1_CellValueNeeded;
this.radVirtualGrid1.CellFormatting += radVirtualGrid1_CellFormatting;
this.radVirtualGrid1.EnablePaging = true;
this.radVirtualGrid1.PageSize = 20;
}
private void radVirtualGrid1_CellFormatting(object sender, VirtualGridCellElementEventArgs e)
{
if (e.CellElement.ColumnIndex < 0 && e.CellElement.RowIndex > -1)
{
e.CellElement.DrawText = true;
e.CellElement.Text = e.CellElement.RowIndex.ToString();
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawTextProperty, ValueResetFlags.Local);
}
}
private void radVirtualGrid1_CellValueNeeded(object sender, VirtualGridCellValueNeededEventArgs e)
{
e.Value = "Data " + e.RowIndex + "." + e.ColumnIndex;
}