New to Telerik UI for WinFormsStart a free 30-day trial

Row Numbers in RadVirtualGrid

Updated over 6 months ago

Environment

Product VersionProductAuthor
2020.1.113RadVirtualGrid for WinFormsDesislava Yordanova

Description

This article shows how to display row numbers in RadVirtualGrid.

row-numbers-in-virtualgrid 001

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;
        }
        
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support