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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





28700 May 7,2005 04:15 AM UTC May 10,2005 08:24 AM UTC WinForms 5
Tags: GridControl
david bosak
Asked On May 7, 2005 04:15 AM UTC

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

Administrator [Syncfusion]
Replied On 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; 

david bosak
Replied On 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!

Administrator [Syncfusion]
Replied On 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.

david bosak
Replied On 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!

Administrator [Syncfusion]
Replied On 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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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