
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:
But this doesn't work.
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
0
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.
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:
it doesn't work.
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
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.
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:
And afterwards
And now I've set this in the CellFormattin-event:
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!
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]" ); |
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
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.
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.