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

Cell Formatting

I want to format the cellvalue to the format like #.000. I tried several events, like QueryCellInfo.., it did not work. Please see the attached example code, and see what''s the problem. Thanks.

Forum_407350.zip

2 Replies

AD Administrator Syncfusion Team March 15, 2006 11:38 AM UTC

Hi Hui, This happens, because the ( e.Style.CellValue = dt.Rows[e.RowIndex - 1][e.ColIndex – 1] ) value of the datatable that is assigned to the cellvalue becomes a string by default. This causes the format not to be assigned. You can avoid this, by converting the value to double. Here is the code snippet. private void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e) { if (e.RowIndex > 0 && e.ColIndex >= 4 ) { e.Style.CellValue = Convert.ToDouble(dt.Rows[e.RowIndex - 1][e.ColIndex - 1]); e.Style.Format = "##.000"; } } Let us know if this helps. Best regards, Madhan.


HZ Hui Zhong March 15, 2006 05:06 PM UTC

Thanks. It worked. >Hi Hui, > > This happens, because the ( e.Style.CellValue = dt.Rows[e.RowIndex - 1][e.ColIndex – 1] ) value of the datatable that is assigned to the cellvalue becomes a string by default. This causes the format not to be assigned. You can avoid this, by converting the value to double. Here is the code snippet. > > private void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e) >{ > if (e.RowIndex > 0 && e.ColIndex >= 4 ) > { > e.Style.CellValue = Convert.ToDouble(dt.Rows[e.RowIndex - 1][e.ColIndex - 1]); > e.Style.Format = "##.000"; > } >} > >Let us know if this helps. > >Best regards, >Madhan.

Loader.
Live Chat Icon For mobile
Up arrow icon