Katalogerna
PlexityHide

Home 

Products 

Downloads 

Our Shop 

Support 

Contact 


GTP.NET FAQ 11092


Resize columns by automagic Please note that this article refers to the GTP.NET
Jump to article- 2007-12-21 12:53:00 - Email plexityHide

Question

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.

 

Thank you.

Answer

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

 

 

Google
WWW plexityHide GTP.NET FAQ
Support

Support intro

Knowledgebase

FAQ phGantTimePackage

FAQ GTP.NET

FAQ general

Testimonials

"This is too GREAT. I must say you have strong support and really good programmers at your place. Your entire team is good. Just Fantastic! – 100%"
Gaurav Patole,
WebTechDevelopers
More testimonials...