How to ResizeToFit a cell with multi-line text in WinForms GridGroupingControl?
Display multi-line text
By default, the WinForms
GridGroupingControl does not have direct support to ReSizeToFit the
multi-line text. It can be displayed only by scrolling.
Solution:
To ReSizeToFit the
multi-line text, a workaround solution in the QueryRowHeight event
is available. In this event, the cell’s height has been calculated as per the
current cell value along with the number of lines.
C#
//Event hooking in constructor.
this.gridGroupingControl1.TableModel.QueryRowHeight += new GridRowColSizeEventHandler(TableModel_QueryRowHeight);
//This event is triggered when the row height is changed.
void TableModel_QueryRowHeight(object sender, GridRowColSizeEventArgs e)
{
if (e.Index > 0)
{
IGraphicsProvider graphicsProvider = this.gridGroupingControl1.TableModel.GetGraphicsProvider();
Graphics g = graphicsProvider.Graphics;
GridStyleInfo style = this.gridGroupingControl1.TableModel[e.Index, 2];
GridCellModelBase model = style.CellModel;
e.Size = model.CalculatePreferredCellSize(g, e.Index, 2, style, GridQueryBounds.Height).Height;
e.Handled = true;
}
}VB
'Event hooking.
AddHandler gridGroupingControl1.TableModel.QueryRowHeight, AddressOf TableModel_QueryRowHeight
'This event gets triggered when the row height is changed.
Private Sub TableModel_QueryRowHeight(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
If e.Index > 0 Then
Dim graphicsProvider As IGraphicsProvider = Me.gridGroupingControl1.TableModel.GetGraphicsProvider()
Dim g As Graphics = graphicsProvider.Graphics
Dim style As GridStyleInfo = Me.gridGroupingControl1.TableModel(e.Index, 2)
Dim model As GridCellModelBase = style.CellModel
e.Size = model.CalculatePreferredCellSize(g, e.Index, 2, style, GridQueryBounds.Height).Height
e.Handled = True
End If
End Sub Note:
Since the height has been calculated in the QueryRowHeight event, which triggers frequently, the row height cannot be resized.
The
screenshot illustrates the multiline text

Figure 1: Multi-line text ReSizedToFit
Samples:
Conclusion
I hope you
enjoyed learning about how to ResizeToFit a cell with multi-line text in
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!