We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Setting BackColor for each level

Hi, How can I set the different ‘BackColor’ for each level when using GDBG in a hierarchical view? Based on the user action and data each ‘level’ will dynamically change the ‘BackColor’. I can’t do that at design time or at the time of form load. I have to do this runtime in response to a user action. I understand that I need to do something like level.RowStyle.BackColor = Color.Red; But I don’t know how to get all the ‘levels’. Starting from ‘root’ to the last level. Thanks, Philip

4 Replies

AD Administrator Syncfusion Team June 8, 2005 09:15 AM UTC

Given a grid row index, you can get the level index for the row using: GridBoundRecordState state = this.grid.Binder.GetRecordStateAtRowIndex(rowIndex); int levelIndex = state.LevelIndex; Then you can use GridHierarchyLevel level = this.grid.Binder.GetHierarchyLevel(levelIndex) to get the GridHierarchyLevel if you know the level index you want.


AD Administrator Syncfusion Team June 8, 2005 02:02 PM UTC

If I know that I have 3 levels in my grid then can I use GridHierarchyLevel level = this.grid.Binder.GetHierarchyLevel(0) GridHierarchyLevel level = this.grid.Binder.GetHierarchyLevel(1) GridHierarchyLevel level = this.grid.Binder.GetHierarchyLevel(2) Or I have to go thru the ‘GetRecordStateAtRowIndex’, my problem is that this way I have to loop thru each row of the grid and then get the levelindex and then actual level. Please advise. thanks, Philip


AD Administrator Syncfusion Team June 8, 2005 02:28 PM UTC

Can i use your suggestion/code in prepareviewstyle event or its too late? Philip


AD Administrator Syncfusion Team June 8, 2005 06:14 PM UTC

In PrepareViewStyleInfo, I think you can use code like this:
if(e.RowIndex > grid.Model.Rows.HeaderCount)
{
     GridBoundRecordState state = this.grid.Binder.GetRecordStateAtRowIndex(rowIndex);
     int levelIndex = state.LevelIndex;
     if(levelIndex == 0)
         e.Style.BackColor = Color.Red;
     else if(levelIndex == 1)
         e.Style.BackColor = Color.Blue;
     else
         e.Style.BackColor = Color.Green;
}

Loader.
Live Chat Icon For mobile
Up arrow icon