How to optimize the ResizeToFit method for large number of records in WinForms GridGroupingControl?
Optimize the ResizeToFit method
The mechanism of the ResizetoFit 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 WinForms GridGroupingControl, 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#
// Event triggering
this.gridGroupingControl1.TableControlVScrollPixelPosChanged += new GridTableControlScrollPositionChangedEventHandler(gridGroupingControl1_TableControlVScrollPixelPosChanged);
void gridGroupingControl1_TableControlVScrollPixelPosChanged(object sender, GridTableControlScrollPositionChangedEventArgs e)
{
// Denotes the top visible row index of the grid.
int top_rowIndex = this.gridGroupingControl1.TableControl.TopRowIndex;
// ViewLayout.VisibleRows gives you the number of visible rows in the ViewLayout.
int bottom_rowindex = top_rowIndex +
this.gridGroupingControl1.TableControl.ViewLayout.VisibleRows;
this.gridGroupingControl1.TableModel.ColWidths.ResizeToFit(
GridRangeInfo.Cells(
top_rowIndex,
0,
bottom_rowindex,
this.gridGroupingControl1.TableModel.ColCount),
GridResizeToFitOptions.IncludeHeaders |
GridResizeToFitOptions.IncludeCellsWithinCoveredRange);
}'Event triggering
AddHandler gridGroupingControl1.TableControlVScrollPixelPosChanged, AddressOf gridGroupingControl1_TableControlVScrollPixelPosChanged
Private Sub gridGroupingControl1_TableControlVScrollPixelPosChanged(ByVal sender As Object, ByVal e As GridTableControlScrollPositionChangedEventArgs)
'Denotes the top visible row index of the grid.
Dim top_rowIndex As Integer = gridGroupingControl1.TableControl.TopRowIndex
'ViewLayout.VisibleRows gives you the number of visible rows in the ViewLayout.
Dim bottom_rowindex As Integer = top_rowIndex +
gridGroupingControl1.TableControl.ViewLayout.VisibleRows
gridGroupingControl1.TableModel.ColWidths.ResizeToFit(
GridRangeInfo.Cells(
top_rowIndex,
0,
bottom_rowindex,
gridGroupingControl1.TableModel.ColCount),
GridResizeToFitOptions.IncludeHeaders Or
GridResizeToFitOptions.IncludeCellsWithinCoveredRange)
End SubC#
//Event trigerring.
this.gridGroupingControl1.TableModel.QueryColWidth += new GridRowColSizeEventHandler(TableModel_QueryColWidth);
void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
if (e.Index > 0)
// Add the condition which satisfy your needs.
e.Size = 150;
} VB
' Event triggering
AddHandler gridGroupingControl1.TableModel.QueryColWidth, AddressOf TableModel_QueryColWidth
Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
If e.Index > 0 Then ' Add the condition which satisfy your needs.
e.Size = 150
End If
End SubSamples:
C#: ResizeToFit_CS
VB: ResizeToFit_VB
Conclusion
I hope you enjoyed learning about how to optimize the ResizeToFit method for a large number of records in the WinForms GridGroupingControl.
You can refer to our WinForms GridGroupingControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridGroupingControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!