)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to ResizeToFit a cell with multi-line text in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: May 26, 2015 |
Last Revised Date: December 24, 2019

Display multi-line text

By default, the 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 QueryRowHeight event that triggers frequently, the row height cannot be resized.

 

ScreenShot:

Display the multiline text in GridGroupingControl

Figure 1: Multi-line text ReSizedToFit

Samples:

C#: DisplayMultilineText

VB: DisplayMultilineText

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon