11092 : Resize columns by automagic


I would like to have the columns in my grid autosize to encompass the longest value.  How can I do this?  For example if column 1 of row 1 has a value of ‘IT’ and column 1 of row 2 has a value of ‘Accounting’ then the size of column 1 should be wide enough to see all of the word ‘Accounting’ without the user having to increase the size manually every time.

< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

Thank you.


You will need to do this yourself by detecting values in the cells and meassure them, then change the width of the column.

I would implement OnGridPaintBackground, not that I will draw anything, but this will be called when the data is in place and the screen must update. I would loop thru the nodes on screen (Grid.GridStructure.VisibleNodes) and loop thru each cell finding out the widest entry in each column (by meassuring the content using the Graphics object in the OnGridPaintBackground event arguments). Once I have this information I need to compare it with the current GridColumn widths.  And if my “rules” says that the widths should change, change them. BUT it is important that you only change the widths if it is necessary, since the change will trigger a need for a new drawing pass (calling OnGridPaintBackground again). You can easily get into recursion if you change the display in an event that draws the display… But once you are aware of the risk it should be controllable.



To catch changing values implement OnAfterEditCell, to set the initialsetup I would