How do I set Column header text in GridControl

I have a nicely working set of GridControls in a gridNavigationControl, complete in all respects except one that is giving me a headache. I can't figure out how to set the text in the GridControl column headers. I can make them show the numbers (a,b,c) or nothing, but I can't define any text. I have tried all the approaches suggested in the demos etc., such as (GridControl[0,1].Text = "xxx", to using datasources bound through PopulateHeaders method, using different forms of datasource arrays, etc., etc., I also can't create SortHeaders with the up/down icons. Basically, I seem to have lost all control of content and styles on all my GridControls Header cells. Maybe someone has a nice suggestions or workaround. Is there a way to draw directly into those cells?

4 Replies

RD Robert Dickow September 1, 2018 08:41 PM UTC

Partial success:  I was able to set the column header text in the event handler Grid.QueryCellInfo. But I guess then that it doesn't have an effect later to set the headers?



AA Arulraj A Syncfusion Team September 3, 2018 12:04 PM UTC

Hi Robert, 

Thanks for using Syncfusion product. 

We have tried to reproduce your scenario using below attached sample. We have tried with your mentioned implementation 
  1. Change header individual cells using below code,
Code example 
this.gridControl1[0, 2].Text = "Column2"; 
 
  1. Tried with PopulateHeaders method. Please refer the following code example,
Code example 
this.gridControl1.PopulateHeaders(GridRangeInfo.Cells(0, 1, gridControl1.RowCount, gridControl1.ColCount), dt); 

But the above code is working fine as we expected. Please let us know the below attached sample differ from your customization.  


As per your update, you can use the QueryCellInfo event to change the header text which is also our one of the approach to change the header text. Please refer to the below KB link, 

To use the sort icon in headers or customize the sort icon or implement the custom sorting. Please refer the following KB links, 

Sort icon in header, 
 
Sort icon customization, 

Custom sorting 

Please let us know if you have any concerns. 

Arulraj A 



RD Robert Dickow September 11, 2018 07:55 PM UTC

The problem I am having is actually simple. If I try to set Cell styles, say, the BackColor property in an event handler , nothing happens. I see that in my implementation, the GridControl is firing the .QueryCellInfo handler after my own event handlers. So, let's say I have a button Click handler that tries to change a cell style using grid[r,c].BackColor, it will not work. However, if I change a cell's BackColor inside the QueryCellInfo handler, the color changes properly in the cell. I can not change any cell characteristics or header styles or content from my handlers, only from the QueryCellInfo handler.


Maybe I have something set up incorrectly, because my control event handlers are processed before the GridControl.QueryCellInfo handler??

I define the grid control's QueryCellInfo event handler vectors during the MetroForm constructor, so maybe I need to change the order of defining my event handlers? I'll try that.

Bob


MG Mohanraj Gunasekaran Syncfusion Team September 12, 2018 12:43 PM UTC

Hi Robert, 
 
Thanks for your update. 
 
By default, QueryCellInfo event handler triggers for every cells and ever actions(Mouse Move, Mouse hover, click and cell invalidation). So, if you have any changes in this event, the changes will be reflected for GridControl. So, can you please ensure your changes and let us know if you have any concerns. If it is possible, please provide your customization, it will be helpful to assist you. 
 
Regards, 
Mohanraj G  


Loader.
Up arrow icon