)
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 change the header text in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 27, 2016 |
Last Revised Date: December 17, 2019

Change header text

To change the column names by using the following ways.

  1. BaseStylesMap
  2. QueryCellInfo
  3. RowStyles

To change the column name by using BaseStylesMap as below.

C#:

gridControl1.BaseStylesMap["Column Header"].StyleInfo.Text="Trial";

 

VB:

gridControl1.BaseStylesMap("Column Header").StyleInfo.Text="Trial"

 

To change the column name by using QueryCellInfo as below.

C#:

this.gridControl1.QueryCellInfo += gridControl1_QueryCellInfo;
}
private void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    if (e.RowIndex == 0 && e.ColIndex > 0)
    {
        e.Style.Text = "Trial" + e.ColIndex;
    }
}

 

VB:

Private Me.gridControl1.QueryCellInfo += AddressOf gridControl1_QueryCellInfo
}
Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
 If e.RowIndex = 0 AndAlso e.ColIndex > 0 Then
  e.Style.Text = "Trial" & e.ColIndex
 End If
End Sub

 

To change the column name by using RowStyles as below.

C#:

for (int k = 1; k <= gridControl1.ColCount; k++)
{
    this.gridControl1[0, k].CellValue = "Trial" + k;
}

 

VB:

For k As Integer = 1 To gridControl1.ColCount
 Me.gridControl1(0, k).CellValue = "Trial" & k
Next k

 

Change the header text in GridControl

Samples:

C#: Change header text

VB: Change header text

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Robert Dickow
Sep 03, 2018

I found that setting the column header text during the QueryCellInfo handler works well. This technique solves my problem. I found that some of the other techniques do not work for me for some reason. For example, as a test I set the GridControl Enter event handler as follows:  In this code the status bar label updates with the word "Howdy" but the grid control column header is unchanged.

// C#` 

private void EnterTest(object sender, EventArgs e)
{
   gridControl[0, 4].CellValue = "Howdy"; // does not alter column header text as expected
   statusStripLabel.Text = "Howdy";  // to visually verify execution of handler
   gridControl.Refresh();  // just to be sure.

}

`

Reply
Mohanraj Gunasekaran [Syncfusion]
Sep 04, 2018

Hi Robert,

 

Thanks for using Syncfusion product.

 

We have tried with your reported scenario in Enter event handler. But, it is working fine as we expected. We suspect that you may tried to change the header text using QueryCellInfo and GridControl[0,4].CellValue property. If you have used both code in your implementation, QueryCellInfo changes will be reflected in GridControl. If you have used different approach, please provide the more information to reproduce the reported scenario. It will be helpful us to proceed further

 

Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/cs-1786788512

 

Regards,

Mohanraj G

Reply

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