Using winforms in vs2008. I have a DataGridView and I would like to detect when the vertical scroll bar is visible. What event should I register for?
I am adding the
Instead of using Linq (Adam Butler) you can just iterate through the controls and sign up an event handler that will be called each time the scrollbar visibility changes. I implemented it that way and it works pretty smoothly:
private System.Windows.Forms.DataGridView dgCounterValues;
private Int32 _DataGridViewScrollbarWidth;
// get vertical scrollbar visibility handler
foreach (Control c in dgCounterValues.Controls)
if (c.GetType().ToString().Contains("VScrollBar"))
{
c.VisibleChanged += c_VisibleChanged;
}
do this somewhere after the InitializeComponent() In the handler, do whatever you need to do in response to the visibility change of the vertical scrollbar. Same works for the horizontal scrollbar (replace VScrollBar with HScrollBar):
void c_VisibleChanged(object sender, EventArgs e)
{
VScrollBar vb = sender as VScrollBar;
if (vb.Visible) _DataGridViewScrollbarWidth = vb.Width;
else _DataGridViewScrollbarWidth = 0;
}