How to display "..." in a cell with WinForms Grid controls?
Trimming text
You can show the cell’s content like “…” at the end while it’s not enough to display the whole text, by setting the GridStyleInfo's Trimming property. In a WinForms WinForms GridControl to set the trimming for an entire column, use the following code example.
Using GridModel
C#
// GridControl this.gridControl1.ColStyles[2].Trimming = StringTrimming.EllipsisWord; // GridGroupingControl this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.WrapText = false; this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.Trimming = StringTrimming.EllipsisWord; // GridDataBoundGrid this.gridDataBoundGrid1.Binder.InternalColumns["ColumnName"].StyleInfo.Trimming = StringTrimming.EllipsisWord;
VB
' GridControl Me.gridControl1.ColStyles(2).Trimming = StringTrimming.EllipsisWord ' GridGroupingControl Me.gridGroupingControl1.TableDescriptor.Columns("ColumnName").Appearance.AnyRecordFieldCell.WrapText = False Me.gridGroupingControl1.TableDescriptor.Columns("ColumnName").Appearance.AnyRecordFieldCell.Trimming = StringTrimming.EllipsisWord ' GridDataBoundGrid Me.gridDataBoundGrid1.Binder.InternalColumns("ColumnName").StyleInfo.Trimming = StringTrimming.EllipsisWord
Using QueryCellInfo
C#
//Hook the event to set the trimming style to the column this.gridControl1.QueryCellInfo += gridControl1_QueryCellInfo; void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if(e.ColIndex == 2) { //Apply trimming for the column e.Style.Trimming = StringTrimming.EllipsisWord; } }
VB
'Hook the event to set the trimming style to the column Me.gridControl1.QueryCellInfo += gridControl1_QueryCellInfo Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) If e.ColIndex = 2 Then 'Apply trimming for the column e.Style.Trimming = StringTrimming.EllipsisWord End If End Sub
The following screenshot illustrates the output.
Figure 1: GridControl with EllipsisWord Trimming
Conclusion
I hope you enjoyed learning about how to display "..." in a cell while the whole text is not enough wide in WinForms GridControl, GridGroupingControl and GridDataBoundGrid.
You can refer to our WinForms Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our 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 ASP.NET MVC Chart and other ASP.NET MVC 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!