Articles in this section
Category / Section

How to display the long text in header cells as viewable in WinForms GridControl?

1 min read

Display the column header text

By default, the cell value will be displayed as per the data that we provided to the grid. In this case, if the particular column has the data with minimum length i.e. 3 to 4 characters and header text as long, the column will be resized as per the header text length.

                          Display the long column header text

In order to display the column header text fully and resize the column based on the data, the Orientation property can be used to display the header text as vertically.

GridControl

C#

for (int j = 0; j < this.grid.ColCount; j++)
{
   style1 = grid[0, j];
   font = style1.Font;
   //Rotate the text of Column header using array values
   font.Orientation = 270; 
   style1.Text = "Angle" + j.ToString();
}

 

VB

For j As Integer = 0 To Me.grid.ColCount – 1
   style1 = grid(0, j)
   font = style1.Font
   'Rotate the text of Column header using array values
   font.Orientation = 270
   style1.Text = "Angle" & j.ToString()
Next j

 

GridGrouping Control

C#

private void btnchange_Click(object sender, EventArgs e)
{
   foreach (GridColumnDescriptor column in     this.gridGroupingControl1.TableDescriptor.Columns)
   {
      column.Appearance.ColumnHeaderCell.Font.Orientation = 270;   
   }
}

 

VB

Private Sub btnchange_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnchange.Click
   For Each column As GridColumnDescriptor In    Me.gridGroupingControl1.TableDescriptor.Columns
     column.Appearance.ColumnHeaderCell.Font.Orientation = 270
   Next column 
End Sub

 

Screenshot

CellGrid

Display the long column header text in cellgrid

DataGrid

Display the long column header text in datagrid

Samples:

C#: Header Alignment_CS

VB: Header Alignment_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