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

Sub-totals and Grand-Total

8 Answers 329 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Eric Moreau asked on 08 Sep 2010, 02:02 PM
Hi have been looking around for quite some time now and I cannot find exactly what I want.

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

Sort by
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 10 Sep 2010, 11:14 AM
Is this forum monitored?
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 10 Sep 2010, 11:30 AM
I found that I can add this code:

 

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?

 

0
Accepted
Martin Vasilev
Telerik team
answered on 13 Sep 2010, 03:09 PM
Hi Eric Moreau,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
george mcnitt
Top achievements
Rank 1
answered on 29 Sep 2010, 06:11 PM
I tried using this code but it never fires. When the ViewCellFormatting event fires no cells ever trigger as GridSummaryCellElement.

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?

 

0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 29 Sep 2010, 06:17 PM
have you added the Handles clause on the event signature?
0
george mcnitt
Top achievements
Rank 1
answered on 29 Sep 2010, 06:26 PM
if you mean the ViewCellFormatting event then yes. Here is the complete code for that event.
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
0
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 03 Oct 2010, 08:27 PM
When I initialize the grid, I use this code :

 

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.
0
Martin Vasilev
Telerik team
answered on 04 Oct 2010, 05:33 PM
Hello guys,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Eric Moreau
Top achievements
Rank 2
Iron
Iron
Veteran
Martin Vasilev
Telerik team
george mcnitt
Top achievements
Rank 1
Share this question
or