Sub-totals and Grand-Total

9 posts, 1 answers
  1. Eric Moreau
    Eric Moreau avatar
    22 posts
    Member since:
    Sep 2007

    Posted 08 Sep 2010 Link to this post

    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.
  2. Eric Moreau
    Eric Moreau avatar
    22 posts
    Member since:
    Sep 2007

    Posted 10 Sep 2010 Link to this post

    Is this forum monitored?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Eric Moreau
    Eric Moreau avatar
    22 posts
    Member since:
    Sep 2007

    Posted 10 Sep 2010 Link to this post

    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?

     

  5. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 13 Sep 2010 Link to this post

    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
  6. george mcnitt
    george mcnitt avatar
    14 posts
    Member since:
    May 2010

    Posted 29 Sep 2010 Link to this post

    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?

     

  7. Eric Moreau
    Eric Moreau avatar
    22 posts
    Member since:
    Sep 2007

    Posted 29 Sep 2010 Link to this post

    have you added the Handles clause on the event signature?
  8. george mcnitt
    george mcnitt avatar
    14 posts
    Member since:
    May 2010

    Posted 29 Sep 2010 Link to this post

    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
  9. Eric Moreau
    Eric Moreau avatar
    22 posts
    Member since:
    Sep 2007

    Posted 03 Oct 2010 Link to this post

    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.
  10. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 04 Oct 2010 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready