This is a migrated thread and some comments may be shown as answers.

Smart FormatString Decimal columns

6 Answers 194 Views
GridView
This is a migrated thread and some comments may be shown as answers.
reza
Top achievements
Rank 1
reza asked on 05 Aug 2014, 10:17 AM
hi

I have a sql table with a Decimal(15,2) data type; so in sql server query result  grid it shows me all values of that column with 2 decimal plcae such as :

242.00
12.31
20.45
37.10
75.90
105.00

when I bind this table to RadGridView and creat a decimal column (without any FormatString) for that field , RadGrid shows me the same result again; is there any FormatString that force the column to hide zero decimal parts and only show real decimal part, such as :

​242
12.31
20.45
37.1
75.9
105

Thanks.

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 06 Aug 2014, 02:02 PM
Hi Reza,

Thank you for writing.

On my side the grid is formatted like in you requirement by default. This is why I have attached my sample project. Could you please check it and let me know how it differs from your real setup? 

I am looking forward to your reply.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
reza
Top achievements
Rank 1
answered on 06 Aug 2014, 03:23 PM
hi
Thnak for reply; I check your attached project and the result was the same as you replied; but please bind your grid to a SqlServer table with a decimal(18,2) columns and check if you see the extra trailing zeros ofter decimal point?
I tested {0:G} and :{0:0.##} format and trailing zeros was disappeared in display time ; but in editing I have them agian (in your project they are existing too); so let me know if there any way for disappearing those useless zeros especially in editing time?

Thanks agin
0
reza
Top achievements
Rank 1
answered on 11 Aug 2014, 06:43 AM
hi
did you check my reply?
0
Dimitar
Telerik team
answered on 11 Aug 2014, 10:38 AM
Hi Reza,

Thank you for writing back.

First I want to say that the zeroes are existing in the mentioned specific case. In addition such format string will remove them.

To remove the zeroes at edit time you can manually trim the text of the hosted textbox control. This can be done when the editor is initialized and when the user is changing the text:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    GridSpinEditor editor = e.ActiveEditor as GridSpinEditor;
    if (editor != null)
    {
        GridSpinEditorElement el = editor.EditorElement as GridSpinEditorElement;
        el.TextChanged -= el_TextChanged;
        el.TextChanged += el_TextChanged;
        el.TextBoxItem.TextBoxControl.Text = el.TextBoxItem.TextBoxControl.Text.TrimEnd('0');
 
    }
}
 
void el_TextChanged(object sender, EventArgs e)
{
    GridSpinEditorElement el = sender as GridSpinEditorElement;
     el.TextBoxItem.TextBoxControl.Text =  el.TextBoxItem.TextBoxControl.Text.TrimEnd('0');
 
}

Please note that all threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
reza
Top achievements
Rank 1
answered on 11 Aug 2014, 01:45 PM
Hi Dimitar
Thanks for your quick reply; I understand your policy for threads handling, but you've answered the first time at same day and there is no reply from your side for more than 5 days! so I supposed you did not see my reply simply! anyway thanks again for reply and I'll check your solution.
0
Dimitar
Telerik team
answered on 12 Aug 2014, 12:25 PM
Hi Reza,

Thank you for writing back.

Please note that the response time depends on license and the current load. Usually, for trial users we reply within 72 hours (business days only), and often we are not getting close to this time frame, however, depending on the load, we might. 

If you have any questions, please do not hesitate to contact us.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
reza
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
reza
Top achievements
Rank 1
Share this question
or