hi guys,
Whats the easiest way to set a default max column width on a win grid?
I have a dataset where some columns have a lot of text, and when I bind the column width is rather large.
Many Thanks
Gary
Hi Gary,
There's a MaxWidth property on the column. The InitializeLayout event is typically a good place to set this.
If you want to enforce the maximum only initially, and still allow the user to resize the column larger later on, then I think what you probably need to do is handle InitializeLayout and just examine the width of the column and if it's bigger than you want, set the Width to a smaller value. You could even call PerformAutoResize on the column first or CalculateAutoResizeWidth to determine the auto-sized width, then just make it smaller as you like.
My question is similar. My UltraGrid pops up with fixed-width columns that have a fair amount of whitespace to the right of the data in most columns. The last column is a Description column that could run on for 80 characters, so I expect it to be truncated.
Is there a property that I can set to have the grid auto-size the columns optimally on the initial load to fit the column data tightly? (Except for the last column, I expect it would be restricted by the Max Width column property.)
I would rather not write InitializeLayout code to examine the data in each row of each column to find and set an optimal display size. It seems to me the grid code (that you guys write :-)) should be able to do this and just give me a property setting. I tried the AutoFitStyle property, but that acts to fit fixed-width columns to window resize events, not fitting the columns to data. Thank you.
There's no property for this, but you can call the PerformAutoResize method on the column. This method will honor the MaxWidth and MinWidth.