Hi,
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,
Yifei
AD
Administrator
Syncfusion Team
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,
Haneef
YH
Yifei Hong
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!
AD
Administrator
Syncfusion Team
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\4.4.0.49\windows\Grid.Windows\Samples\Appearance\TextFormat\cs
Best regards,
Haneef