Articles in this section
Category / Section

How to customize the column name in GroupDropArea of WinForms GridGroupingControl?

1 min read

Column customization

The column name in GroupDropArea can be customized by using PrepareViewStyleInfo and QueryColWidth events of GridGroupDropArea.

C#

void Model_QueryColWidth(object sender, Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs e)
{
   GridGroupDropAreaModel grid = sender as GridGroupDropAreaModel;
   if (grid.Model[2, e.Index].CellValue != null && grid.Model[2, e.Index].CellValue.ToString().Contains("\n"))
   {
      GridStyleInfo style = grid.Model[2, e.Index];
      e.Size = this.SetTextWidth(style.Text, style.GdipFont) + 20;
                e.Handled = true;
   }
}
//Customize the column name in GropuDropArea.
void GridGroupDropArea_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
   if (e.Style.CellValue.ToString().Contains("\n"))
   {
      e.Style.Text = e.Style.CellValue.ToString().Replace("\n", " ");
   }
}
//Customize the column name in GroupCaptionCell.
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
   if (e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell)
   {
      //To change the group caption text.
      e.Style.Text = e.Style.Text.Replace("\n", " ");
   }
}

 

VB

Private Sub Model_QueryColWidth(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs)
   Dim grid As GridGroupDropAreaModel = TryCast(sender, GridGroupDropAreaModel)
   If grid.Model(2, e.Index).CellValue IsNot Nothing AndAlso grid.Model(2, e.Index).CellValue.ToString().Contains(Constants.vbLf) Then
      Dim style As GridStyleInfo = grid.Model(2, e.Index)
      e.Size = Me.SetTextWidth(style.Text, style.GdipFont) + 20
      e.Handled = True
   End If
End Sub
'Customize the column name in GropuDropArea.
Private Sub GridGroupDropArea_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs)
   If e.Style.CellValue.ToString().Contains(Constants.vbLf) Then
   e.Style.Text = e.Style.CellValue.ToString().Replace(Constants.vbLf, " ")
   End If
End Sub
'Customize the column name in GroupCaptionCell.
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
   If e.TableCellIdentity.TableCellType = GridTableCellType.GroupCaptionCell Then
      'To change the group caption text.
      e.Style.Text = e.Style.Text.Replace(Constants.vbLf, " ")
   End If
End Sub

 

Screenshot

Before Customization

Before customize the column

After Customization

After customize the column

 

Samples:

C#: Customize_Column Name_CS

VB: Customize_Column Name_VB

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied