Is their a way to determine if the DataGridView Scrollbars are
visible?
Is there a way to be notfied when their visible property has changed?
thanks,
p.s. this doesn't work for the datagridview for some reason.
[DllImport("User32", CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int
Index);
private const int GWL_STYLE = (-16);
private const int WS_VSCROLL = 0x200000;
private const int WS_HSCROLL = 0x100000;
bool HasHorizontalScrollbar(Control ctrl)
{
return (GetWindowLong(ctrl.Handle, GWL_STYLE) &
WS_HSCROLL) != 0;
}
bool HasVerticalScrollbar(Control ctrl)
{
return (GetWindowLong(ctrl.Handle, GWL_STYLE) &
WS_VSCROLL) != 0;
}
"TerryFei" - 16 Jan 2006 07:13 GMT
Hi kh,
Thanks for your post.
There are 2 types of Scrollbars:
1. Scrollbar that is created by WS_VSCROLL or WS_HSCROLL window style.
2. Scrollbar control, which is the child control of the parent control.
DataGridView uses the second type of Scrollbar. So we should enumerate
DataGridView’s child controls, then check to see if this scroll bar is
visible. Sample code sinppet listed below:
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.dataGridView1.Controls.Count; i++)
{
if (this.dataGridView1.Controls[i] is VScrollBar)
{
if (this.dataGridView1.Controls[i].Visible)
{
MessageBox.Show("VScrollBar is visible");
}
}
if (this.dataGridView1.Controls[i] is HScrollBar)
{
if (this.dataGridView1.Controls[i].Visible)
{
MessageBox.Show("HScrollBar is visible");
}
}
}
}
This code snippet works well on my side. Hope it helps
Best regards,
Terry Fei
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
>From: Chuck@newsgroup.nospam
>Subject: DataGridView ScrollBars
[quoted text clipped - 9 lines]
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.windowsforms.controls:26442
>X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms.controls
>
[quoted text clipped - 25 lines]
>WS_VSCROLL) != 0;
> }
Chuck@newsgroup.nospam - 21 Jan 2006 02:42 GMT
perfect, thanks
>Hi kh,
>Thanks for your post.
[quoted text clipped - 79 lines]
>>WS_VSCROLL) != 0;
>> }
"Jeffrey Tan[MSFT]" - 23 Jan 2006 05:55 GMT
You are welcome
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 18 Jan 2006 07:55 GMT
Hi Chuck,
Does my colleague Terry's reply make sense to you? If you still need any
help, please feel free to feedback. Thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights