Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
785
Subtotals Rows with Merged Cells.
posted

So I have a grid and I have merged "rows" together via certain columns containing identical values.

".MergedCellStyle = MergedCellStyle.Always.MergedCellStyle = MergedCellStyle.Always"

So what I want to do would seem to be a common task but I'm not seeing an answer.  I want to create a "summary" for the "quantity" column of the rows that were merged together.   I don't want to group the rows like normal because I like the look of the "merged" cells for this particular grid.  AND I only want to display a total if more than one row is merged.

What am I missing?  I'm pretty good with using draw filters, but the only way I could see to use a draw filter would be if there was something that fired AFTER the last cell was merged but before the next row was created. 

I guess I could come up with a brute force way of doing this, but it just seems like it would be a common thing and I'm just missing something.

Parents Reply Children
  • 785
    Offline posted in reply to Mike Saltzman

    Thanks Mike,

    I decided to go at it with a draw filter.  That way I didn't have to worry about the update events.  Here is what I my grid looks like:

     

    In case some else wants to to do this and not have to think to much<G>:

     

        Public Function GetPhasesToFilter(ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Infragistics.Win.DrawPhase Implements Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter

            Dim rVal As Infragistics.Win.DrawPhase = DrawPhase.None


            If (TypeOf (drawParams.Element) Is MergedCellUIElement) Then

                Dim mrgCell As Infragistics.Win.UltraWinGrid.MergedCellUIElement
                mrgCell = TryCast(drawParams.Element, MergedCellUIElement)

                If mrgCell IsNot Nothing AndAlso mrgCell.Cell.Row.IsDataRow Then
                    rVal = Infragistics.Win.DrawPhase.BeforeDrawElement
                End If


            End If

     

            Return rVal
        End Function

        Dim LastRawID As Integer = -1

     

        Public Function DrawElement(ByVal drawPhase As Infragistics.Win.DrawPhase, ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Boolean Implements Infragistics.Win.IUIElementDrawFilter.DrawElement

            Dim rVal As Boolean = True
            Dim elementRect As Rectangle
            Dim g As Graphics = drawParams.Graphics
            elementRect = drawParams.Element.Rect


            If (TypeOf (drawParams.Element) Is MergedCellUIElement) Then

                'Load up some variables that releate to the cell.
                Dim theRow As UltraGridRow
                Dim theCol As Infragistics.Win.UltraWinGrid.UltraGridColumn
                Dim theCell As Infragistics.Win.UltraWinGrid.UltraGridCell
                Dim mrgCell As Infragistics.Win.UltraWinGrid.MergedCellUIElement

                mrgCell = TryCast(drawParams.Element, MergedCellUIElement)
                theRow = mrgCell.Cell.Row
                theCol = mrgCell.Cell.Column
                theCell = mrgCell.Cell

                'Grid has several merged columns, so I only want to do the spacing for the first column   
                If theCol.Key = "RawItemDescrp2" Then
                    Dim cRow As Integer = 0

                    'This is the KEY of the current merged row.
                    Dim theRawID As Integer = theRow.Cells("RawID").Value
                    Dim QtyTot As Integer = 0

                    'Loop thru the rows in the child band where we have merged cells
                    For Each mRow As UltraGridRow In theRow.ParentRow.ChildBands(0).Rows

                        If mRow.Cells("RawID").Value = theRawID Then
                            cRow += 1
                            QtyTot += mRow.Cells("ReqQty").Value  'Total up merged rows
                        ElseIf cRow > 1 Then
                            'Once we have found another item then put some space between them.
                            mRow.RowSpacingBefore = 30
                            cRow = 0
                        End If

                    Next

                    If cRow > 1 Then
                        'This handles merged rows that are at the end of the child band.
                        theRow.ParentRow.ChildBands(0).Rows(theRow.ParentRow.ChildBands(0).Rows.Count - 1).RowSpacingAfter = 30
                    End If

                    If QtyTot > 0 Then
                        'This draws my sub total box
                        Dim theRCell As CellUIElement = theRow.Cells("ReqQty").GetUIElement()
                        Dim tRec As New Rectangle(theRCell.Rect.X + 1, elementRect.Y + elementRect.Height, theRCell.Rect.Width - 2, theRCell.Rect.Height)
                        g.DrawString(QtyTot, mrgFont, Brushes.Black, tRec, mrgTotStrFmt)
                        g.DrawRectangle(Pens.Black, tRec)


                    End If

                End If

                ' I didn't like how the Merged Cell was rendering the text.  I wanted it to word wrap.
                g.FillRectangle(New SolidBrush(Color.FromArgb(100, Color.Green)), elementRect)
                g.DrawString(theCell.Value, mrgFont, Brushes.Black, elementRect, mrgStrFmt)

                rVal = True ' I handled the drawing of the element so I don't want the default drawing.

            End If

            Return rVal
        End Function