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
1158
Code to known if a UltraGrid have Scrollbar Visible.
posted

Hi to all, I've search here if some one have any idea to know if a UG showns any ScrollBar. With xamDataGrid there is a property that expose related info, but  UltraGrid have not.

I wrote a static method wich may be do this work:

/// <param name="ug"></param>
/// <returns>0= none, 1= horiz, 2 = vert, 3 = both</returns>
public static int HasScrollBarsVisible(UltraGrid ug)
{
 
int r = 0;
 RowColRegionIntersectionUIElement uiCSR = ug.DisplayLayout.ColScrollRegions[0].GetUIElement(ug.DisplayLayout.RowScrollRegions[0]);//ug.ActiveColScrollRegion.GetUIElement(ug.ActiveRowScrollRegion);
 object o = uiCSR.Parent.GetDescendant(typeof(ColScrollbarUIElement));
 ColScrollbarUIElement uiCScrollbar = o as ColScrollbarUIElement;
 if (null != uiCScrollbar) { r += 1; }
 o = uiCSR.Parent.GetDescendant(
typeof(RowScrollbarUIElement));
 RowScrollbarUIElement uiRScrollbar = o as RowScrollbarUIElement;
 if (null != uiRScrollbar) {r += 2;}
 return r;
}

The code search in the UIElements of UG if there are the UIElements of ScrollBars ;)

Mind the gap!! the code check ONLY the first RowColRegion, if you have a splitted UG change the code to check desidered RowColRegion (R,C).

I hope this help.

Have a nice sunday.
Davide Dolla.

  • 1320
    Offline posted

    Hey Davide great code - thanks for that.  I have taken it further so that it can be used as an extender method under VB 2008 and have also taken advantage of Microsoft ScollBars enumeration as follows:

    Imports System.Runtime.CompilerServices
    Imports Infragistics.Win.UltraWinGrid
    Public Module modUltraGridExtenders
      ''' <summary>
      ''' Determine if either or both of the scrollbars are visible on this UltraGrid control.
      ''' </summary>
      ''' <param name="gridControl">The UltraGrid in question.</param>
      ''' <returns>0 if none are visible; 1 if only the Horizontal scrollbar is visible; 2 if only the Vertical scrollbar is visible; or 3 if both scrollbars are visible.</returns>
     
    ''' <remarks></remarks>
     
    <Extension()> _
     
    Public Function ScrollBarVisibility(ByVal gridControl As UltraGrid) As System.Windows.Forms.ScrollBars
       
    Dim r As Integer = 0
       
    If gridControl.DisplayLayout.ColScrollRegions.Count > 0 AndAlso gridControl.DisplayLayout.RowScrollRegions.Count > 0 Then
         
    Dim uiCSR As RowColRegionIntersectionUIElement = gridControl.DisplayLayout.ColScrollRegions(0).GetUIElement(gridControl.DisplayLayout.RowScrollRegions(0))
         
    Dim o As Object = uiCSR.Parent.GetDescendant(GetType(ColScrollbarUIElement))
         
    Dim uiCScrollbar As ColScrollbarUIElement = TryCast(o, ColScrollbarUIElement)
         
    If uiCScrollbar IsNot Nothing Then
           
    r += 1
         
    End If
         
    o = uiCSR.Parent.GetDescendant(GetType(RowScrollbarUIElement))
         
    Dim uiRScrollbar As RowScrollbarUIElement = TryCast(o, RowScrollbarUIElement)
         
    If uiRScrollbar IsNot Nothing Then
           
    r += 2
         
    End If
       
    End If
       
    Return CType(r, System.Windows.Forms.ScrollBars)
      End Function
    End
    Module