I have a GridView (Q2 2010), I group some rows programmatically.
Now I need to display sub-totals and the grand-total for 3 columns. I have only been able to display the 3 sub-totals on different lines.
What is the the correct way of adding sub-totals (based on grouping) for the 3 columns on the same line?
How to add the Grand-total line for those 3 columns?
All this is set programmatically.
8 Answers, 1 is accepted
Dim item1 As New GridViewSummaryRowItem
item1.Add(
New GridViewSummaryItem("MarketValue", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("CumGainLoss", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("GainLossUnrealized", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("Pct", kGridFormatNumberDec4NZ, GridAggregateFunction.Sum))
.MasterTemplate.SummaryRowsBottom.Add(item1)
.MasterTemplate.ShowTotals =
True
Now how can my values by right aligned just like the other values in the columns?
Thank you for writing.
I am glad that you have found out how to implement summary items that suit your requirements. Once you set up them, you can apply format and text alignment through the ViewCellFormatting event. Please consider the following code:
Private
Sub
radGridView1_ViewCellFormatting(sender
As
Object
, e
As
CellFormattingEventArgs)
If
TypeOf
e.CellElement
Is
GridSummaryCellElement
Then
e.CellElement.TextAlignment = ContentAlignment.MiddleLeft
End
If
End
Sub
I hope this helps. Let me know if you have any other questions.
All the best,
Martin Vasilev
the Telerik team
I am using the code below to add the summary rows, also the ShowTotals never shows eaither.
Dim summary As New GridViewSummaryItem("descr", " Count: {0} ", GridAggregateFunction.Count)
Me.grdResults.MasterTemplate.SummaryRowGroupHeaders.Add(New GridViewSummaryRowItem(New GridViewSummaryItem() {summary}))
Dim summary2 As New GridViewSummaryItem("dur", " Duration: {0} ", GridAggregateFunction.Sum)
Me.grdResults.MasterTemplate.SummaryRowGroupHeaders.Add(New GridViewSummaryRowItem(New GridViewSummaryItem() {summary2}))
grdResults.MasterTemplate.ShowTotals =
True
Any Ideas?
THe ViewCellFormatting event does fire just the code in it below never excutes when it finds a GridSummaryCellElement.
Like its not detecting any of the cells are of type GridSummaryCellElement.
Private
Sub
grdResults_ViewCellFormatting(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.CellFormattingEventArgs)
Handles
grdResults.ViewCellFormatting
If
TypeOf
e.CellElement
Is
GridSummaryCellElement
Then
Dim
summaryCellFont
As
Font =
New
Font(
"Verdana"
, 10)
e.CellElement.DrawBorder =
True
e.CellElement.DrawFill =
True
e.CellElement.NumberOfColors = 1
e.CellElement.BackColor = Color.Crimson
e.CellElement.Font = summaryCellFont
e.CellElement.TextAlignment = ContentAlignment.MiddleLeft
End
If
End
Sub
Dim item1 As New GridViewSummaryRowItem
item1.Add(
New GridViewSummaryItem("MarketValue", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("CumGainLoss", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("GainLossUnrealized", kGridFormatNumberDec2NZ, GridAggregateFunction.Sum))
item1.Add(
New GridViewSummaryItem("Pct", kGridFormatNumberDec4NZ, GridAggregateFunction.Sum))
grdResults
.MasterTemplate.SummaryRowsBottom.Add(item1)
grdResults
.MasterTemplate.ShowTotals =
True
You have a GridViewSummaryItem object while I use the GridViewSummaryRowItem object.
George, the ViewCellFormatting event does not work in your case, because you are putting your summaries into GroupHeader rows. In this case, you cannot make separate formatting for your summaries, because they are inseparable part of the GroupHeader row element. Still, you can format GridGroupHeaderRowElements:
Private
Sub
radGridView1_ViewRowFormatting(sender
As
Object
, e
As
RowFormattingEventArgs)
If
TypeOf
e.RowElement
Is
GridGroupHeaderRowElement
Then
e.RowElement.DrawFill =
True
e.RowElement.BackColor = Color.Red
e.RowElement.NumberOfColors = 1
e.RowElement.ForeColor = Color.White
End
If
End
Sub
I hope this helps. Let me know if you have any other questions.
Best wishes,
Martin Vasilev
the Telerik team