Hi to All. I need to calculate the vertical distance of all rows above the top most row shown in a grid containing collapsible regions. For example, in the grid below there are rows above the top row (i.e. the first "Phase 2" row) - some being collapsed and some not. Any ideas? Or am I going to have to iterate over the rows with some funky logic?
There's nothing built-in to the grid for this. You will have to loop and try to account for borders, overlapping rows, headers, scrollbars, etc.
You should Submit a feature request to Infragistics
BTW.. isn't Mr. Jetson's first name George? :)
George Jetson? I think you might be right Mike, but now you're showing your age too!
For the benefit of any future readers of this post I have come up with this function:
Private Function VisibleHeightAbove(ByVal rows As RowsCollection, ByVal fromRow As UltraGridRow, ByRef height As Integer) As BooleanDim terminate As Boolean = FalseFor Each row As UltraGridRow In rows If terminate Or row Is fromRow Then terminate = True Exit For End If height += row.Height If TypeOf row Is UltraGridGroupByRow Then Dim groupByRow As UltraGridGroupByRow = row If groupByRow.IsExpanded Then terminate = VisibleHeightAbove(groupByRow.Rows, fromRow, height) End If End IfNextReturn terminateEnd Function
This can then be called from the grid control's AfterRowRegionScroll event like this:
Private Sub UltraGrid1_AfterRowRegionScroll(ByVal sender As Object, ByVal e As RowScrollRegionEventArgs) Handles UltraGrid1.AfterRowRegionScrollIf e.RowScrollRegion.VisibleRows.Count > 0 Then Dim spaceAbove As Integer = 0 Dim firstVisibleRow As UltraGridRow = e.RowScrollRegion.VisibleRows(0).Row If firstVisibleRow IsNot Nothing Then VisibleHeightAbove(UltraGrid1.Rows, firstVisibleRow, spaceAbove) End If 'Then do what you want with "spaceAbove"End IfEnd Sub