Hi,
my wingrid is displayed in a panel and the dockstyle is set to fill and scrollbars appear. How can I determine the actual size of the wingrid?
Is this possible at all?
regards
Stefan
Hi Stefan,
You can determine the size of any control using it's Size property. Size is a property on Control, it's not specific to the grid.
but I want to know the "real" size because at design time I don not now how many rows are in the grid or what font is being used. I want to resize the parent container of the grid so that I do not get scrollbars.
I'm not sure what you mean by the "real" size. The Size property of the control returns the actual on-screen size of the control. It's not a fake size.
It sounds like maybe you mean you want to size the grid control to it's contents, but there's no way to do that. You can size the columns to the width of the grid using the AutoFitStyle property. But there's no way to size the grid automatically to fit the rows. You might be abale to calculate the size yourself by multipling the row height times the number of rows, but you would need to account for borders and headers and such.
What event you use depends on when you want the size. If you just want the initial size, you could probably just put the code immediately following the settings of the grid's Data Source. Although, it might be better to wait until the Paint event of the grid fires the first time so you can be sure all the UIElements have been created in case you need them to determine the size of something.
stevonix said:By the way doesn't the scrollbar "know" how many pixels there are left in the height? Is there a possibility to access the scrollbar and get the height information?
No, because the scrolling is row-based, not pixel based.
Hi Mike,
determining the height of the grid inclusive the rows is what I want. Counting rows etc. manually would probably be a solution. Which event would be best to do this ? (there is no AfterIntializeLayout :-( )
By the way doesn't the scrollbar "know" how many pixels there are left in the height? Is there a possibility to access the scrollbar and get the height information?