AutoResizeColumnHeadersHeight only works if I set a breakpoint!
Using VB.Net I want to automatically size the height of the headers in a DataGridView so I am calling AutoResizeColumnHeadersHeight during the form load after the data has been populated.
The method doesn't appear to do anything, but does work if I do the following: - put a breakpoint on grid.AutoResizeColumnHeadersHeight() - open quickwatch on the grid - expand the child properties - close quickwatch and hit F5 to continue processing
The resizing then works!
I assume the reason is that evaluating one of the properties of the grid is causing the method to behave differently.
Does anybody know either wha开发者_StackOverflowt I should be doing differently, or a workaround - e.g. which property do I need to evaluate to make it work?
Are you 100% sure this code runs in the Load event? Using the Handle property ensures that the control window is created and that it will automatically scale to adjust to the machine's video adapter and system font settings. That should never be necessary if the code actually runs due to the Load event, all Handles of all controls will have been created by then.
Note that AutoResizeColumnHeadersHeight() is actually for manual resizing, it only works once. Although it automatically calculates the height. To get automatic resizing, set the ColumnHeadersHeightSizeMode property to AutoSize.
Found a workaround, the method works correctly if I add a line before like:
Dim workaround As System.IntPtr = grid.Handle
grid.AutoResizeColumnHeadersHeight()
I'd still be interested in a better answer though.
精彩评论