This is a migrated thread and some comments may be shown as answers.

Group header row color

2 Answers 446 Views
GridView
This is a migrated thread and some comments may be shown as answers.
yaron
Top achievements
Rank 1
yaron asked on 23 Jan 2020, 03:29 AM

Hi,

I have a grouped radgridview.

What I am trying to accomplish is, when a regular (not group row) row is selected, I would like to change the background color of it's group row so it will be easy to see it (the group row of the selected regular row).

For example - 

Group Row A

1

2

3

Group Row B

4

5

if the user selects the row "2" I want "Group Row A" to change color. If the user then selects row "4" I want "Group row B" to change color (and "Group Row A" to change back to it's default color).

 

I have succeeded to change the color of the group row when selecting the group row directly (through the ViewRowFormatting event) but can not do it in a good way when a regular row is selected (in the SelectionChnaged event). I tried using:

1) From SelectionChanged event calling  this.gridView.TableElement.Update(GridUINotifyAction.Reset) but it brings the table back to the top if the user scrolled down.

2) From SelectionChanged  - tried to get the group row of the selected row and change it's background. Can not find the way to get to the GroupRowElement where I can access the background property.

Please help, any advice to achieve this would be appreciated!

Yaron

 

 

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jan 2020, 02:32 PM

Hello, Yaron,  

The appropriate place to format the grid cells/rows is to use the ViewCellFormatting/ViewRowFormatting events, not the SelectionChanged event. In other events you can just mark certain data rows for highlighting, e.g. via the data row's Tag property and then use this Tag value in the formatting event that you are using. The following help articles demonstrate how to customize the grid cells/rows:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells 
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows 

If you need to trigger firing the event for a certain row, it is necessary to call the InvalidateRow method for the respective data row. Calling the MasterTemplate.Refresh method will reset the view and the vertical scrollbar will go to the top. You can keep the vertical scrollbar's value before refreshing and restore its value after that. It is necessary to store the TableElement.VScrollBar.Value property and restore it later.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
n/a
Top achievements
Rank 1
answered on 27 Jan 2020, 02:38 PM

Thank you for the tips and clarifications.

I will use the info you gave me and hopefully I will succeed.

Thanks again

Tags
GridView
Asked by
yaron
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
n/a
Top achievements
Rank 1
Share this question
or