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

Style groupings

5 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas Van den Bossche
Top achievements
Rank 1
Thomas Van den Bossche asked on 16 Oct 2009, 09:19 AM
Hi,

What's the best way to style the header of the groupings?
Now I'm looping through all the rows after the databind like this:
foreach ( GridViewRowInfo row in grid.Rows ) { 
  if ( row is GridViewGroupRowInfo ) { 
    row.VisualElement.DrawFill = true
    row.VisualElement.BackColor = Color.Red; 
  } 

But this doesn't work.


5 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 16 Oct 2009, 10:14 AM
Hello Thomas Van den Bossche,

If you want to do that with code, I suggest using ViewCellFormatting event.

Greetings,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Thomas Van den Bossche
Top achievements
Rank 1
answered on 16 Oct 2009, 10:35 AM
I have to set the style of the header grouping after all the rows are drawn because I've set the "group by" programmatically.
If I'm using the CellFormatting-event, it's too late...

If I'm looping through the rows afterwards:
foreach ( GridViewDataRowInfo row in gridAssigned.Rows ) { 
                GridViewCellInfo cell = row.Cells[ 0 ]; 
 
                if ( cell.CellElement != null ) { 
                    if ( cell.CellElement.RowInfo is GridViewGroupRowInfo ) { 
                        cell.CellElement.DrawFill = true
                        cell.CellElement.BackColor = Color.Red; 
                        cell.CellElement.TextAlignment = ContentAlignment.MiddleRight; 
                        cell.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid; 
                    } 
                } 
            } 

it doesn't work.


0
Nick
Telerik team
answered on 16 Oct 2009, 10:48 AM
Hi Thomas Van den Bossche,

The only safe place to apply visual formatting to cells and rows is cell formatting because RadGridView employs virtualization and hence the visual elements are reused. I think that even if the grouping is created programmatically, ViewCellFormatting can still be used. Actually when you set grouping, ViewCellFormatting will be invoked for all necessary cells(cells that need update of their visual state). Please elaborate a little bit more on your scenario.

Greetings,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Thomas Van den Bossche
Top achievements
Rank 1
answered on 16 Oct 2009, 11:50 AM
First of all I'm filling up the DataGrid:

foreach ( SalesOrder orderline in order.Lines ) { 
                    int rowIndex = gridSAP.Rows.Add( 
                                            new object[]{ 
                                                    driver, 
                                                    orderline.ShipTo, 
                                                    orderline.MatDescription 
                                                } 
                                        ); 
                } 


And afterwards
gridSAP.MasterGridViewTemplate.GroupByExpressions.Add( "[Driver] AS Driver Group By [Driver]" ); 
And now I've set this in the CellFormattin-event:
private void SetGroupStyle( object sender, CellFormattingEventArgs e ) { 
            if ( e.CellElement.RowInfo is GridViewGroupRowInfo ) { 
                e.CellElement.DrawFill = true
                e.CellElement.BackColor = Color.Red; 
                e.CellElement.TextAlignment = ContentAlignment.MiddleRight; 
                e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid; 
            } 
        } 

But nothing is changing. If I change "is GridViewGroupRowInfo" to "is GridViewDataRowInfo" the layout is applied to the cells but not to the header of the grouping.

Thanks in advance!


0
Accepted
Nick
Telerik team
answered on 16 Oct 2009, 12:32 PM
Hello Thomas Van den Bossche,

You have to use ViewCellFormatting instead of CellFormatting as explained in the help article. The if statement will never execute because CellFormatting is never raised for non-data cells.

Best wishes,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Thomas Van den Bossche
Top achievements
Rank 1
Answers by
Nick
Telerik team
Thomas Van den Bossche
Top achievements
Rank 1
Share this question
or