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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to optimize the ResizeToFit method for large number of records?

The mechanism of ResiztoFit() method is that it checks each value of the cells and its width and then calculates the width of the column. So when you check for rows above 44k, it takes more time than expected. The solution for this problem is, you can apply the ResizetoFit() method only for the visible layout. That is, instead of applying the ResizetoFit() method to the whole grid, you can apply this method to the viewable cells. You can get the viewable cells row and column index by using the TableControlVScrollPixelPosChanged event.

Refer to the following code examples for the TableControlVScrollPixelPosChanged event.

C#

 

VB

Another suggestion is that you can use the QueryColWidth event instead of using ResizeToFit() method. Refer to the following code example. In this event, you can change the size of each column with the help of index value.

C#

 

VB

 

Sample Links:

C#: ResizeToFit_CS

VB: ResizeToFit_VB

Article ID: Published Date: Last Revised Date: Platform: Control:
4853 05/13/2015 05/13/2015 WinForms GridGroupingControl
Tags:
Did you find this information helpful?
Comments
Sergei Leschinksy Jun 25, 2015
I tried both methods to adjust heights of rows in GridGroupingControl. The problems I encountered with first example: a) when scrolling reaches the end of the grid it fails (a check is needed that bottom_rowindex is within bounds); b) when you scroll too fast it fails with NullReference exception at ResizeToFit (I don't know why, all indices are within range); c) the last row in the table may fall outside the scroll bar reach, so it can't be displayed. The second method is somewhat better. But there are still issues which block its use: a) several last rows in most cases fall outside scrollbar reach (when I tested it with 10000 records, I missed 6 rows); b) when I scroll the grid with mouse wheel there are rendering glitches (rows are displayed with insufficient height at first), strange but other scrolling methods (keyboard, dragging scrollbar) don't suffer from it. I wonder, does anybody succeeded to implement either one of these approaches without glitches, including the esteemed author of these recipes?
Reply
QLT User Mar 30, 2016
i am not sure this sample works. the header column does not resize to fit
Reply
Amresh Soundhra Pandiyan [Syncfusion] Mar 31, 2016
Hi QLT User, For re-sizing the column headers please us the following code for applying ReSizeToFit() method in the TableControlVScrollPixelPosChanged event method. CodeExampe: this.gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Cell(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex), GridResizeToFitOptions.IncludeHeaders);
QLT User Oct 24, 2016
if I decide not to go with the 1st option and use this code instead.


            gridTabbedStrategies.TableModel.ColWidths.ResizeToFit(
                GridRangeInfo.Cols(0, gridTabbedStrategies.TableModel.ActiveGridView.ViewLayout.VisibleCols), GridResizeToFitOptions.IncludeHeaders);

it seems like my my whole  grid settings vanish. why is that ?



Reply
QLT User Oct 24, 2016
if I decide not to go with the 1st option and use this code instead.


            gridTabbedStrategies.TableModel.ColWidths.ResizeToFit(
                GridRangeInfo.Cols(0, gridTabbedStrategies.TableModel.ActiveGridView.ViewLayout.VisibleCols), GridResizeToFitOptions.IncludeHeaders);

it seems like my my whole  grid settings vanish. why is that ?



Reply
Mohanraj Gunasekaran [Syncfusion] Oct 26, 2016

Hi QLT User,

 

We have tried your code part in our sample. But we are not able to reproduce your scenario at our end. Can you please provide the customization for your sample? it will be helpful to provide the solution at the earliest.

 

Regards,

Mohanraj G.

Add Comment
You must log in to leave a comment

Warning Icon 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.Close Icon