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
690
Scroll Context (fixed row for parent records)
posted

Hi,

This is a tricky one to explain, so I'll try my hardest with diagrams.

Assume you've got a very big grid, with say, 4 levels of parent/child bands.

Now when scrolling down, the parent level (red and blue) is out of view, leaving the items shown in the final child band.

What I want, is when the top row is in the 4th band, fix the parent (red) band rows to the top of the grid, almost like a "floating" row. The sibling rows of the parent bands still appear to scroll, and the "top floating" band gets replaced when the set of topmost rows hits the next band.

I'm sure there's a better name for this, and a better explanation!

Thanks, Tom

Parents Reply
  • 690
    posted in reply to Tom

    Here's some code for Mike and anyone else that's interested:

    UPDATE: Formatted: http://pastebin.com/UnPNv25T

        Private m_IsMouseWheeling As Boolean
        Private m_MouseScrollUpdate As Thread
        Private Sub grdAuthorised_MouseWheel(sender As Object, e As MouseEventArgs) Handles grdAuthorised.MouseWheel
            m_IsMouseWheeling = e.Delta <> 0
        End Sub
        Private Sub grdAuthorised_AfterRowRegionScroll(sender As Object, e As RowScrollRegionEventArgs) Handles grdAuthorised.AfterRowRegionScroll
                'Debug.WriteLine("Scrolling to " & e.RowScrollRegion.ScrollPosition)
                If Not m_IsMouseWheeling Then
                    UpdateGridScrollContext()
                Else
                    If m_MouseScrollUpdate Is Nothing Then '-- Don't judge me here
                        m_MouseScrollUpdate = New Thread(Sub()
                                                             Thread.Sleep(50)
                                                             Invoke(New Action(AddressOf UpdateGridScrollContext)) '-- UI thread
                                                             m_MouseScrollUpdate = Nothing '-- Lose the ref, do it again
                                                             m_IsMouseWheeling = False '-- Hack!
                                                         End Sub)
                        m_MouseScrollUpdate.Start()
                    End If
                End If
        End Sub
        Private Sub UpdateGridScrollContext()
            If InvokeRequired Then
                Invoke(New Action(AddressOf UpdateGridScrollContext))
                Exit Sub
            End If
            flpAdvancedLayoutContext.SuspendDrawing() '-- Helper to actually suspend redraws
            Dim value As New AdvancedContext("(none)") '-- All labels will show (none) if not filled by the context helper below
            Dim topmostRow As UltraGridRow = grdAuthorised.ActiveRowScrollRegion.FirstRow
            If topmostRow IsNot Nothing Then
                If topmostRow.IsSummaryRow Or topmostRow.IsFilterRow Then
                    topmostRow = topmostRow.ParentRow
                End If
                If topmostRow IsNot Nothing Then
                    value = GetAdvancedContext(topmostRow.ListObject, value)
                End If
            End If
            lblContextBusinessLine.Text = value.BusinessLine
            lblContextCompany.Text = value.CompanyGroup
            lblContextAccountCode.Text = value.AccountCode
            lblContextPurchaseOrder.Text = value.PurchaseOrder
            flpAdvancedLayoutContext.ResumeDrawing()
        End Sub
        Private Structure AdvancedContext
            Public BusinessLine As String
            Public CompanyGroup As String
            Public AccountCode As String
            Public PurchaseOrder As String
            Public Sub New(defaultString As String)
                BusinessLine = defaultString
                CompanyGroup = defaultString
                AccountCode = defaultString
                PurchaseOrder = defaultString
            End Sub
        End Structure
        Private Function GetAdvancedContext(context As Object, value As AdvancedContext) As AdvancedContext
            If TypeOf context Is InvoiceGroupBusinessLine Then
                value.BusinessLine = CType(context, InvoiceGroupBusinessLine).BusinessLine.Name
            ElseIf TypeOf context Is InvoiceGroupCompanyGroup Then
                value.CompanyGroup = CType(context, InvoiceGroupCompanyGroup).CompanyGroup.Name
                Return GetAdvancedContext(CType(context, InvoiceGroupCompanyGroup).Parent, value)
            ElseIf TypeOf context Is InvoiceGroupRecipient Then
                value.AccountCode = CType(context, InvoiceGroupRecipient).Location.SageAccountCode
                Return GetAdvancedContext(CType(context, InvoiceGroupRecipient).Parent, value)
            ElseIf TypeOf context Is InvoiceGroupPurchaseOrder Then
                value.PurchaseOrder = CType(context, InvoiceGroupPurchaseOrder).PurchaseOrder
                Return GetAdvancedContext(CType(context, InvoiceGroupPurchaseOrder).Parent, value)
            ElseIf TypeOf context Is LabRefForInvoicing Then
                Return GetAdvancedContext(CType(context, LabRefForInvoicing).Parent, value) '-- Parent is an InvoiceGroupPurchaseOrder
            End If
            Return value
        End Function

Children
No Data