Groups | Blog | Home
all groups > vb.net controls > september 2005 >

vb.net controls : How does DataGrid calculate its ScrollBars' settings?


nate axtell
9/7/2005 8:11:06 AM
In VB .NET I've created custom TextBox columns that auto-adjust row height
due to wrapping and multi-line text. The VScrollBar doesn't have the
correct settings after the heights are adjusted, so it doesn't scroll down
to show the entire list of data. It appears to be calculating the Maximum
and/or Changes incorrectly with regard to the adjusted row heights.
Note: I am ajusting row heights within the GetMinimumHeight method of the
TextBox column class. So when the DataGrid actually goes to paint a row it
has the correct height that it needs stored in the "get_DataGridRows"
collection.
Is there a way that I can find the total height of the scrollable area, not
just clientarea hight?
Or does anyone have another suggestion on how to manipulate the DataGrid's
VScrollBar?
I was thinking about checking the values and changing them in the DataGrid's
Paint method.

Ken Tucker [MVP]
9/8/2005 7:46:38 AM
Hi,

I usually adjust the size of the grid to get the scrollbars to
recalculate the size. I make grid 1 pixel smaller than bring it back to the
orginal size.

Ken
-----------------
[quoted text, click to view]

nate axtell
9/14/2005 8:35:29 AM
For anyone else that has this problem, or is interested, I found that the
DataGrid calculates the LargeChange to the number of displayed
TotallyVisible rows. So if the rows get larger as you scroll down there
will not be enough scroll bar positions available to see all of the rows
(depending on heights). To fix this I calculate what the LargeChange should
be on the Grid's size changes and when the Grid is sorted. I also do this
calculation the first time the Grid is Painted.
I determined that the LargeChange should calculated looking at the largest
heights and working my way toward the smaller heights. I add up larger
heights until I can't fits anymore in the height of the grid. I take this
number of totally visible, tallest rows and set the LargeChange equal to it.
-n

[quoted text, click to view]

AddThis Social Bookmark Button