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 change the TextAlign in QueryCellInfo()

Thread ID:





58226 Mar 21,2007 12:44 AM UTC Mar 21,2007 05:08 PM UTC WinForms 3
Tags: GridControl
Yifei Hong
Asked On March 21, 2007 12:44 AM UTC


I override QueryCellInfo() in my custom GridControl class which inherits from Syncfusion.Windows.Forms.Grid.GridControl. I was trying to change the text alignment as the default setting is left-aligned. My code is as below,

private void gridControl_QueryCellInfo( object sender, GridQueryCellInfoEventArgs e )
e.Style.TextAlign = GridTextAlign.Right;
e.Handled = true;

But the code does not seem to take effect and the text alignment in grid cells is still the same as default left-aligned.

The second question is that if I only want to show 2 digits after decimal point for double values. How do I do it? Also how can I show '123456789' as '123,456,789'?

Thanks a lot for your great help and I really appreciate for your time.

Best Regards,

Administrator [Syncfusion]
Replied On March 21, 2007 02:16 PM UTC

Hi Yifei,

Issue 1: TextAlignment.

Use the HorizontalAlignment property of the GridStyleInfo object to specify the horizontal cell text alignment in a grid. Here is a code snippet.

private void gridControl_QueryCellInfo( object sender, GridQueryCellInfoEventArgs e )
e.Style.HorizontalAlignment = GridHorizontalAlignment.Right;
e.Handled = true;

Issue 2:

Here code that displays 2 decimal places. Make sure you also set the CellValueType for your cells.

this.grid.Model.ColStyles[1].CellValueType = typeof(double);
this.grid.Model.ColStyles[1].CellValue = 1.1d;
this.grid.Model.ColStyles[1].Format = "F2";

Best regards,

Yifei Hong
Replied On March 21, 2007 04:48 PM UTC

Thanks a lot! Haneef

Your help is always timely and informational. What you suggested does achieve the purpose.

Btw, is there anyway to show '123456789' as '123,456,789'?

Thanks again!

Administrator [Syncfusion]
Replied On March 21, 2007 05:08 PM UTC

Hi Yifei,

Thank you for your update.

You can set the Style.Format property to achieve this behavior

//QueryCellInfo event
e.Style.CellValueType = typeof(double);
e.Style.CellValue =123456789d;
e.Style.Format = "##,##"; //use this format "##,##.00" to show 2 decimal points.

Please refer to the TextFormat browse sample that shows you "how to format the data in your grid?"
[install drive]:Syncfusion\Essential Studio\\windows\Grid.Windows\Samples\Appearance\TextFormat\cs

Best regards,


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

or the page will be automatically redirected to 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