Live Chat Icon For mobile
Live Chat Icon

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

Platform: WinForms| Category: Datagrid

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 technique 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

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.