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. Image for the cookie policy date
close icon

How to align the column header when its data is aligned to LEFT?

Hi! For example, the data of "Column1" is aligned to LEFT. How to align the column header as its data? Thanks!

5 Replies

AD Administrator Syncfusion Team May 7, 2005 10:10 AM UTC

To align a column header for a particular column, you can set: grid[0, colIndex].HorizontalAlignment = GridHorizontalAlignment.Left; More generally, you can loop through the column styles and set the style o fthe header cell to match the style of the column.
//in a gridcontrol
for(int i = 1; i <= grid.ColCount; ++i)
    grid[0, i].HorizontalAlignment = grid.ColStyles[i].HorizontalAlignment;

//in a griddataboundgrid
//if you have not added GridBoundColumns
for(int i = 1; i <= grid.Model.ColCount; ++i)
    grid[0, i].HorizontalAlignment = grid.Binder.InternalColumns[i-1].HorizontalAlignment; 

//in a griddataboundgrid
//if you have added GridBoundColumns
for(int i = 1; i <= grid.Model.ColCount; ++i)
    grid[0, i].HorizontalAlignment = grid.GridBoundColumns[i-1].HorizontalAlignment; 



DB david bosak May 9, 2005 11:27 AM UTC

It not work with the following codes: switch (fieldInfo.Align) { case "0": this.dgrQueryResults[0, i].HorizontalAlignment = GridHorizontalAlignment.Left; dgrQueryResults.Model.ColStyles[header].HorizontalAlignment = GridHorizontalAlignment.Left; break; case "1": this.dgrQueryResults[0, i].HorizontalAlignment = GridHorizontalAlignment.Right; dgrQueryResults.Model.ColStyles[header].HorizontalAlignment = GridHorizontalAlignment.Right; break; case "2": this.dgrQueryResults[0, i].HorizontalAlignment = GridHorizontalAlignment.Center; dgrQueryResults.Model.ColStyles[header].HorizontalAlignment = GridHorizontalAlignment.Center; break; } Please help!


AD Administrator Syncfusion Team May 9, 2005 11:55 AM UTC

Are you using a GridControl? Or a GridDataBoundGrid? As shown in the previous snippets, you do not use ColStyles with a GridDataBoundGrid. Instead, you use the StyleInfo object from the appropriate GridBoundColumn collection.


DB david bosak May 10, 2005 03:04 AM UTC

- I am using GridDataBoundGrid - It still work when I use ColStyles[header]: dgrQueryResults.Model.ColStyles[header].HorizontalAlignment = GridHorizontalAlignment.Right; - However, this command did not work: this.dgrQueryResults[0, i].HorizontalAlignment = GridHorizontalAlignment.Right; Please help!


AD Administrator Syncfusion Team May 10, 2005 08:24 AM UTC

I am sorry. You do have to do something special to align header text on a cell by cell basis in a GridDataBoundGrid. You will need to do this in either grid.PrepareViewStyleInfo or in grid.Model.QueryCellInfo. Here is a sample using the PrepareViewStyleInfo event. http://www.syncfusion.com/Support/user/uploads/GDBG_Align_cce59b9a.zip

Loader.
Live Chat Icon For mobile
Up arrow icon