RadGridView: Row Header Related Questions

1 Answer 395 Views
GridView
WEI TZE
Top achievements
Rank 2
Iron
Iron
WEI TZE asked on 15 Sep 2022, 01:42 AM | edited on 15 Sep 2022, 06:48 AM

[C# WinForm]

Regarding the Row Header (as shown in the figure below: (C7, C6,...,C1)

Questions:

  1. How to set the styling of the Row Header the exactly the same as the Column Header?
  2. How to get the Text of the Row Header? (C7, C6,...,C1) - E.g. string rowHeaderText = radGridView1.Rows[0].......

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 15 Sep 2022, 01:45 PM

Hello WEI TZE,

Thank you for the provided image.

RadGridView offers the RowFormatting/ViewRowFormatting and CellFormatting/ViewCellFormatting events which allow you to customize the style of the grid cells/rows. Additional information is available in the following help articles:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows

To customize the non-data cells/rows (header row, new row, filtering row, etc) of RadGridView, you need to handle the ViewCellFormatting/ViewRowFormatting event:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells#formatting-non-data-cells
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows#customize-the-non-data-rows-appearance

In your case, you can subscribe to the ViewCellFormatting of the RadGridView. Inside the vent handler, you can check the e.CellElement property for GridRowHeaderCellElement. Then you could customize the cell per your requirement. Here you could also set the Text property of the row header cell.

private void RadGridView1_ViewCellFormatting1(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridRowHeaderCellElement )
    {       
        e.CellElement.Text = "C1";
        e.CellElement.ForeColor = Color.Blue;
    }
}

As for getting the text of a specific row header cell, you can use the following code.

var cellContent = this.radGridView1.TableElement.VisualRows[0].VisualCells[0].Text;

I hope that you find this information helpful.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
WEI TZE
Top achievements
Rank 2
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or