I need your support about formating numerical data into the datgrid. I made a search in your forum but I didn't find nothing, only information about data date type.
So I wanna knoiw what about numerical data and type float for example.
11 Answers, 1 is accepted
Thank you for the question.
You can set custom format on each column by using the column property DataTextFormatString. For example take a look on code snippet bellow:
private void Form1_Load( object sender, EventArgs e )
{
DataTable dt = new DataTable();//make custom data source with 3 columns
dt.Columns.Add( "col1", typeof( int ) );
dt.Columns.Add( "col2", typeof( float ) );
dt.Columns.Add( "col3", typeof( double ) );//add 3 rows with ID and PI number
dt.Rows.Add( new object[] { 1, Math.PI, Math.PI } );
dt.Rows.Add( new object[] { 2, Math.PI, Math.PI } );
dt.Rows.Add( new object[] { 3, Math.PI, Math.PI } );
this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false;
GridViewDataColumn col1 = new GridViewDataColumn( "col1" );
this.radGridView1.MasterGridViewTemplate.Columns.Add( col1 );
GridViewDataColumn col2 = new GridViewDataColumn( "col2" );
this.radGridView1.MasterGridViewTemplate.Columns.Add( col2 );
//here is the column number formating
col2.DataTextFormatString = "{0:#}";//show only integer part of the number
GridViewDataColumn col3 = new GridViewDataColumn( "col3" );
this.radGridView1.MasterGridViewTemplate.Columns.Add( col3 );
//here is the column number formating
col3.DataTextFormatString = "{0:#.###}";//show 3 numbers after decimal point
this.radGridView1.DataSource = dt;
}
For more information on formatting numbers and text, please review the following link.
Regards,
Peter
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I have column in database with decimal(15,4) and bound to the grid.
I try to format the grid column here using DataTextFormatString={0:g}
It's NOT WORKING. How to use this format? BUT if i change it to DataTextFormatString={0:f} or others format, it works. Why?
Please help.
I will try this.I have another question.I saw that the SP2 radcontrols for winforms is available now and I wonder if I should rebuild all my application(using SP1) with SP2 controls or there is a way to keep the application and perform its using?
Frederik, please read the following article carefully: http://idunno.org/archive/2004/14/01/122.aspx
In this document you can find explanation how to format numbers – especially for {0:g} (g means general). Basically, the output that you will get is the same as format string you have inserted, without any change.
Najoua, if you feel there is no need to upgrade, i.e. SP1 performs fine in your project, there is no need to install and upgrade to SP2. Still, we will recommend using SP2 because we have added several new feature, and have fixed several major issues with our controls.
If you want to use SP2 you have to uninstall SP1first and then install SP2. This will not impact your application, so you should update your project references to use the new assemblies. Basically, you should remove the old DLLs from your application and them again, but from SP2 installation.
Best wishes,
Peter
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I did like you said and I run the application.There is no error when debugging, but some foctionalities don't work.For exemple, I have a double click event in the grid view which occured the show of details row or imprting data...The problem is that that nothing is shown in defined area.
Could you give some suggestion?
Thanks for your help. Yes, I did read the website given. Please give me suggestion. I have table with 4 decimal point ex 100.2300 and in grid show 100.2300. Is it possible to take of the zeros and become 100.23 instead 100.2300 in the grid? The grid is bound to table in database
Other case, value 100.2345 the grid have to show 100.2345.
Please help. What format I have to use?
Eriksurya, if your column is bound as Decimal there is no need to remove any zeros. They are removed automatically. If this is a string column there is no possibility to format the string with RadGridView.ValueFormatting. I would suggest specifying explicitly your column types in the DataSource. If you need additional help please open a support ticket and we will help you out.
Bahri, we will need some more details in order to investigate your issue. Where exactly you are trying to attach on the double click event? Is it possible for you to send us your project? To do so, you must open a support ticket as well.
Sincerely yours,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
How to make the grid removes the decimal automatically? Because my grid doesnt do that. It's bound to table with decimal types. Even i use the datatextformatting in grid {0:g} and still doesnt work. I try {0:f} and it works.
Obviously, to give you an adequate explanation we will need to examine in more details your scenario. Could you please send us a small sample project so we could test it locally. Please note that to do this you should open a support ticket.
Best wishes,
Georgi
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
After further investigation, if you set the data type in SQL SERVER 2005 to decimal (9,4), it will no automatically remove the zeros. And in the grid will show 4 decimal points.
But if you choose float it will automatically remove the zeros and in the grid will show no zeros in decimal points.
Then if I am using decimal data type how to achieve like float datatype in the grid?
thanks
if you have decimal data type field in the underlaying database you should use GridViewTextBoxColumn or GridViewDecimalColumn depending on how you want to edit values in the respective column in the grid.
In the case of GridViewTextBoxColumn you will be able to edit with a simple textbox editor, while in case in GridViewDecimalColumn there will be a spin editor.
Regardless of the type of column you will use, the formatting will be applied internally using the String.Format method. As the parameter pass the value from the DB as an object and the formatting string from the DataTextFormatString property from the column. You could see how String.Format works from this link: http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx
Kind regards,
Peter
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center