Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

5. Windows Forms Datagrid

5.85 How can I tell whether a scrollbar is visible in my DataGrid is visible?


If you are using a derived DataGrid, then you can check the Visible property on the protected VertScrollBar property of DataGrid. So, you could check Me.VertScrollBar.Visible from within your derived DataGrid.

To check it without access to the protected scrollbar properties is a little more work, but possible. One techigue is to loop through the Controls property of the DataGrid looking for the scrollbar, and then checking its visible property at that time.

[C#]
     //sample usage
     bool vSrollBarVisible = this.IsScrollBarVisible(this.dataGrid1);
     .....

     private bool IsScrollBarVisible(Control aControl)
     {
          foreach(Control c in aControl.Controls)
          {
               if (c.GetType().Equals(typeof(VScrollBar)))
               {
                    return c.Visible;
               }
          }
          return false;
     }

[VB.NET]
     'sample usage
     Dim vScrollBarVisible = Me.IsScrollBarVisible(Me.DataGrid1)
     ......

     Private Function IsScrollBarVisible(ByVal aControl As Control) As Boolean
          Dim c As Control
          For Each c In aControl.Controls
               If c.GetType() Is GetType(VScrollBar) Then
                    Return c.Visible
               End If
          Next
          Return False
     End Function