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

format double value and datetime value in griddataboundgrid

Hi,
I am using a griddataboundgrid to display a datatable. I assign the datatable to the grid as datasource with all the column mapping names predefined. I noticed that the double value is displayed in the cell as 4.1 instead of 4.10, and the datetime type is displayed in the cell as a datetime picker.
I would like to format all double values in the grid as xx.xx format, and want the datetime value be read only text rather than datetime picker.
What is the best way to do this? I dont want to do this on a cell base or even column base, as I hope I dont need to go into the table at runtime and check the data type of each column. I hope this can be configured with the grid table wise at design time. Is it possible?

Thanks.

zheng

5 Replies

HA haneefm Syncfusion Team June 14, 2007 05:48 PM UTC

Hi Zheng,

You can do this by using the GridBoundColumn collection property in a grid. Here is a minimal sample that implement GridBoundColumn collection property to format a column in a grid. Please try the sample and let me know if this helps.

Sample : GDBGCellTypes.zip

Best regards,
Haneef


ZL Zheng Lin June 14, 2007 06:22 PM UTC

Thanks for the quick response!
There are some good tips in your sample that I can use. However, to resolve my exact situation, I have one more hurdle. That is, I am not hard coding the gridboundcolum in my code, but rather, read them in from a xml file, the mapping names and descriptions only. I was hoping that the grid when loading data from the database table, is smart to know what data type each column is and do the formatting accordingly.
In other words, I was hoping that I can somehow configure the format behavior of the grid table in general to handle double fields in certain way and datatime value in certain way. And I dont need to set it specifically for each column. Is that possible? Is the grid able to get value type information from the data table source?
Also I noticed that you are able to achieve the datatime text rather than control by making it "static", can I do something similar to other text box so that user wont be able to select and focus on it?

Thanks again.

zheng


HA haneefm Syncfusion Team June 14, 2007 09:59 PM UTC

Hi Zheng,

If the columns in your DataBase schema are set to numerical type, then the grid should atomatically pick up the proper GridBoundColumn.StyleInfo.CellValueType.

But you will have to set GridBoundColumn.StyleInfo.Format for the columns where you want to see the formatted values. If you have explicitly added GridBoundColumns to the grid.GridBoundColumns collection (either from the designer or within your own code), then you can set the Format property either in teh designer or in your code.

If you have not added GridBoundColumns, then you can use the grid.Binder.InternalColumns collection to set the Format property from within your code after you have set the grid.DataSource property (which creates the grid.Binder.internalColumns collection).

Here is a kb article discussing setting the BackColor property on a column. To set the Format property, you would do something similar.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=85

If you just don’t want to be able to focus on cells , you could consider using GridBoundColumn.StyleInfo.Clickable property . This way,grid cell ignoring the focus. This may make things behave better.

Best regards,
Haneef


ZL Zheng Lin June 18, 2007 11:24 PM UTC


Thanks, Haneef, that works perfect for me. Now I have one more thing to seek the expert's advice.
The double value in my grid column kept showing right aligned in the cell even after I set the styleinfo.gridtextalign to left.
I noticed that in your sample, the double values do show up left aligned, do you know what I might be missing here?

Thanks.

zheng
>Hi Zheng,

If the columns in your DataBase schema are set to numerical type, then the grid should atomatically pick up the proper GridBoundColumn.StyleInfo.CellValueType.

But you will have to set GridBoundColumn.StyleInfo.Format for the columns where you want to see the formatted values. If you have explicitly added GridBoundColumns to the grid.GridBoundColumns collection (either from the designer or within your own code), then you can set the Format property either in teh designer or in your code.

If you have not added GridBoundColumns, then you can use the grid.Binder.InternalColumns collection to set the Format property from within your code after you have set the grid.DataSource property (which creates the grid.Binder.internalColumns collection).

Here is a kb article discussing setting the BackColor property on a column. To set the Format property, you would do something similar.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=85

If you just don’t want to be able to focus on cells , you could consider using GridBoundColumn.StyleInfo.Clickable property . This way,grid cell ignoring the focus. This may make things behave better.

Best regards,
Haneef


ZL Zheng Lin June 18, 2007 11:47 PM UTC

Never mind, I figure it out, it is the "HorizontalAlign" that I should set.

Thanks.

zheng

>
Thanks, Haneef, that works perfect for me. Now I have one more thing to seek the expert's advice.
The double value in my grid column kept showing right aligned in the cell even after I set the styleinfo.gridtextalign to left.
I noticed that in your sample, the double values do show up left aligned, do you know what I might be missing here?

Thanks.

zheng
>Hi Zheng,

If the columns in your DataBase schema are set to numerical type, then the grid should atomatically pick up the proper GridBoundColumn.StyleInfo.CellValueType.

But you will have to set GridBoundColumn.StyleInfo.Format for the columns where you want to see the formatted values. If you have explicitly added GridBoundColumns to the grid.GridBoundColumns collection (either from the designer or within your own code), then you can set the Format property either in teh designer or in your code.

If you have not added GridBoundColumns, then you can use the grid.Binder.InternalColumns collection to set the Format property from within your code after you have set the grid.DataSource property (which creates the grid.Binder.internalColumns collection).

Here is a kb article discussing setting the BackColor property on a column. To set the Format property, you would do something similar.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=85

If you just don’t want to be able to focus on cells , you could consider using GridBoundColumn.StyleInfo.Clickable property . This way,grid cell ignoring the focus. This may make things behave better.

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon