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.
Unfortunately, activation email could not send to your email. Please try again.

Can I format number as comma separated in grid?

Thread ID:

Created:

Updated:

Platform:

Replies:

13486 Apr 29,2004 11:26 AM Apr 30,2004 06:14 AM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On April 29, 2004 11:26 AM

In DataBoundDataGrid, I would like 1000 displayed as 1,000 but still treated as number type, so I can sort it properly. Is there any way to do that? Thanks a lot

Administrator [Syncfusion]
Replied On April 29, 2004 12:09 PM

Try this. Make sure your DataColumn type is int so the grid thinks the column is integer. Then handle the grid.model.QueryCellFormattedText event and format the display text there.
this.gridDataBoundGrid1.Model.QueryCellFormattedText += new GridCellTextEventHandler(gridModel_QueryCellFormattedText);

//the handler
private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
	if(e.Style.CellValueType == typeof(int))
	{
		e.Text = ((int)Style.CellValue).ToString("#,###");
		e.Handled = true;
	}
}

Administrator [Syncfusion]
Replied On April 29, 2004 01:44 PM

THanks. My grid is built based on the DB query dynamically. The fields in DB are types money and deciaml. But it seems that I can not work it out using the follwing function. ANy suggestions? Thanks for your time private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e) { if(e.Style.CellValueType == typeof(double)) { e.Text = ((double)e.Style.CellValue).ToString("#,###"); e.Handled = true; } } >Try this. Make sure your DataColumn type is int so the grid thinks the column is integer. > >Then handle the grid.model.QueryCellFormattedText event and format the display text there. > >
>this.gridDataBoundGrid1.Model.QueryCellFormattedText += new GridCellTextEventHandler(gridModel_QueryCellFormattedText);
>
>//the handler
>private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
>{
>	if(e.Style.CellValueType == typeof(int))
>	{
>		e.Text = ((int)Style.CellValue).ToString("#,###");
>		e.Handled = true;
>	}
>}
>

Administrator [Syncfusion]
Replied On April 30, 2004 06:14 AM

Instead of using the type double in the code, try using the type decimal.

CONFIRMATION

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.

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.

;