First, I posted a similar request for help in another group and now
don't find the posting. Problem with my newsreader perhaps ... but
apologies if this appears as a cross posting.
My code is inconsistent in the detection of a vertical scrollbar. This
involves situations when less than the client area is needed to hold
the small amount of data. The inconsistency is when adjusting the
panel size within or just below the bottom row. Sometimes the code
adjusts the splitter of the panel as if a vertical scrollbar was
present ... when it is not. This results in seeing a portion of the
panel outside the DataGridView where the scrollbar resides when it is
needed.
I use the following code to detect if a vertical scrollbar is present:
grid2.AutoResizeColumns();
grid2.AutoResizeRows();
int i, sum = 0;
for(i = 0; i < grid2.ColumnCount; ++i)
{
sum + grid2.Columns[i].Width;
}
if(grid2.PreferredSize.Height split2.Panel2.ClientSize.Height)
{
// Adjust splitter to fit columns WITH a vertical scrollbar present
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 35);
}
else
{
// Adjust to fit columns WITHOUT a vertical scrollbar present.
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 19);
}
I wish I knew how to directly determine if the vertical scrollbar is
present without using the PreferredSize.Height ClientSize.Height
comparison. Rather than summing the column widths and using the sum
value, I've also used Preferred.Width ... but see the same effect.
I've printed out the Preferred.Width and ClientSize.Height and these
are updating correctly. The problem seems internal of the DataGridView
control itself in that it is obviously using a different determination
for the displaying of the scrollbar. I'm almost convinced this is
actually a flaw of the control that needs to be fixed ... but usually
when I feel this way I find it is because I have done something wrong
and the controls end up being robust.
Thanks for any help sent my way. :)
-- Tom