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.
Unfortunately, activation email could not send to your email. Please try again.

ResizeToFit won''t shrink column widths

Thread ID:

Created:

Updated:

Platform:

Replies:

34089 Sep 1,2005 12:45 PM Sep 2,2005 08:58 AM Windows Forms 7
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 1, 2005 12:45 PM

We have a context menu in our grid that calls ColWidths.ResizeToFit() for all the columns with the ResizeCoveredCells and IncludeHeaders options. Originally I had the NoShrinkSize option but the designers decided they wanted it to shrink as well. When I removed the NoShrinkSize, it still wouldn''t resize down. It has no problem resizing cells larger, however We have a number of custom cell models that implement OnQueryPreferredClientSize. I put a breakpoint in the ResizingColumns event since we do some work in there, but it''s not even getting called. So at this point, I''m stumped. Our grid control is actually derived from the Syncfusion GridControl and there''s a great deal of code, so providing a simple example would be hard. We also have a MouseController derived class that handles column resizing with the mouse, but I don''t think it would interefere with this. I guess I''m just curious what sorts of things might cause the resizing to a smaller size to not work while resizing to a larger size works fine. I''ve just run out of places to look. Thanks. Pete

Administrator [Syncfusion]
Replied On September 1, 2005 01:35 PM

There is a minimum size set for empty cells. It uses a static member of GridCellModelBase, MeasureEmptyCellString, to determines what size the ResizeToFit will use for an empty cell. So if you include the RowHeaders in your resizing range (as the row headers have not text), then this member will trigger a minimum size. GridCellModelBase.MeasureEmptyCellString = "Wg;\r\nWg;"; You said you were including the headers. Are they keeping a column wider than expected for looking at non-header cells. Just eyeballing the code, if the calculated height returns a value or zero, it will not be used. So, you might check if any of your preferred size routines return 0. Another option is to step through the code to see why the size does not change when you expect it.

Administrator [Syncfusion]
Replied On September 1, 2005 03:25 PM

Clay, I traced into it and found the cause of the problem and I don''t know what the solution is: The grid has hidden rows. If the cell isn''t part of a covered cell then: canResize = this.Model.RowHeights[rowIndex] > 0; Well, since this is 0 (because the row is hidden), width = this.Model.ColWidths[colIndex]; This basically precludes the possibility of resizing cells smaller in a grid with hidden rows, which doesn''t really make any sense to me. Is this a bug? Pete

Administrator [Syncfusion]
Replied On September 1, 2005 04:53 PM

I am missing something I think. If the row is not visible, then why would you want the content of any column in that row to affect the resizing?

Administrator [Syncfusion]
Replied On September 1, 2005 05:19 PM

>I am missing something I think. > >If the row is not visible, then why would you want the content of any column in that row to affect the resizing? Clay, maybe I''m missing something. I''m calling ColWidths.ResizeToFit() for all columns. I don''t care about the row in question. I want to resize the width of the columns based on their content. But, the way the GridRowColSizeIndexer.ResizeToFit() fit works, when resizing the COLUMNS, it checks to see if a ROW is hidden. If the ROW is hidden, it uses the current width of the cell as the temporary "width" variable which is then used to decide the minimum width for that entire column. If the ROW isn''t hidden, it calls QueryPreferredClientSize, which in this case is returning a smaller width than the current column width. But since, for hidden rows, it''s using the current column width, I can''t resize the column to a width less than the current width with ResizeToFit. What should really be happening is the row, if hidden, should be ignore entirely. After all, if it''s hidden, it shouldn''t contribute to the ResizeToFit operation one way or the other, n''est pas? I''ve attached an example. Run the app. Click "Toggle Row 2 Hide". This will hide the second row in the grid. Now click "Resize To Fit". Notice the 3rd column does not resize smaller. Now click "Toggle Row 2 Hide" again so that the second row is no longer hidden and click "Resize To Fit", and now the 3rd column resizes down properly. Pete GridResizeToFitBug_6019.zip

Administrator [Syncfusion]
Replied On September 1, 2005 05:23 PM

One other thing. Since we''ve added some customizations to our version of the grid, if you could tell me how to modify the Syncfusion Grid code to work around the bug, that would be great. I would try to fix it myself but for fear of not taking something into consideration and causing problems elsewhere in the resizing. You guys know that code better than I do. Pete

Administrator [Syncfusion]
Replied On September 1, 2005 06:57 PM

Thank you for the sample. Try replacing width = this.Model.ColWidths[colIndex]; with width = this.Model.RowHeights[rowIndex] > 0 ? this.Model.ColWidths[colIndex] : 0;

Administrator [Syncfusion]
Replied On September 2, 2005 08:58 AM

Clay, thanks. Worked like a charm. Pete

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;