We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Virtual grid and auto resizing cols and rows . .

i am using QueryRowHeight and QueryColWidth i want to determine the size for some cols and rows and all the other be autofit based on the value. i am using a virtual grid . . thks, ak

3 Replies

AD Administrator Syncfusion Team August 23, 2005 07:16 AM UTC

You might try this. Have a Hashtable with the keys being some unique ID (could be a col index if you do not allow col moving, or could be a column title or something else unique) for the columns that you want to have a particular size and the values in teh Hashtable being the size. Also have a variable that tracks the total of the cached sizes. Then in QueryColWidth, check to see if e.Index is in teh Hashtable, and if so, return the cached size. If not, then return the (grid.ClientWidth - SumOfCachedSizes) / NumberOfNonCachedColumns. Make sure anytime you change a value in teh Hashtable, you call grid.ResetVolatileData (or grid.Refresh) to be sure the grid forces QueryColWidth to be hit so your new sizes are used. Take a look at this sample. http://www.syncfusion.com/Support/user/uploads/GridColWidthSample_28e65d76.zip When you run it, click the ''specified'' radio button and then click the Apply button. Then size the form so its width changes. You will see certain columns (as specified by the values in teh list) always occupy the specified percentage of the client area using a technique similar to what I suggested above.


AK Adam K. August 23, 2005 11:39 AM UTC

ok, we are getting somewhere but i am not sure if i explained properly i do have a hashtable with the cols that i want to keep track of specific widths (keyed off of colindex) and i do a looking during the QueryColwidth . .that works fine . . the issue is with the other cells. the question is that i don''t want the rest of the cols to simply fill up the client area. I want the rest of the cols to be autosized based on the width of the largest text width in that column does that makes sense. thanks, ak >You might try this. Have a Hashtable with the keys being some unique ID (could be a col index if you do not allow col moving, or could be a column title or something else unique) for the columns that you want to have a particular size and the values in teh Hashtable being the size. Also have a variable that tracks the total of the cached sizes. Then in QueryColWidth, check to see if e.Index is in teh Hashtable, and if so, return the cached size. If not, then return the (grid.ClientWidth - SumOfCachedSizes) / NumberOfNonCachedColumns. > >Make sure anytime you change a value in teh Hashtable, you call grid.ResetVolatileData (or grid.Refresh) to be sure the grid forces QueryColWidth to be hit so your new sizes are used. > >Take a look at this sample. > >http://www.syncfusion.com/Support/user/uploads/GridColWidthSample_28e65d76.zip > >When you run it, click the ''specified'' radio button and then click the Apply button. Then size the form so its width changes. You will see certain columns (as specified by the values in teh list) always occupy the specified percentage of the client area using a technique similar to what I suggested above. >


AD Administrator Syncfusion Team August 23, 2005 01:13 PM UTC

I think the simplest way to do this is to also add the ''other columns'' to your hashtable. When you add them, call grid.Model.ColsWidths.ResizeToFit and set the value in the hashtable based on the returned optimal colwidth. Now as you are making the ResizeToFit call and getting the width by calling grid.Model.ColWidth[col], unhook your QueryColWidth event (or set a flag or something) so that you do not try to provide the colwidth through your handler in this situation.

Loader.
Live Chat Icon For mobile
Up arrow icon