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

Decimal column leading zeros

3 Answers 327 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Danilo
Top achievements
Rank 1
Danilo asked on 09 Jul 2015, 09:40 AM

Hi there

 I'm trying to add rows to a GridViewDecimalColumn with leading zeros. I know there's a property "FormatString" but this is not exactly what I want. I want the numbers always have the same amount of zeros leading. Here you can see my code:

GridViewDecimalColumn col = new GridViewDecimalColumn();
col.FormatString = "{0:0000}";
radGridView1.Columns.Add(col);

This will output the following:

Number 1 will be 0001
Number 2 will be 0002
Number 10 will be 0010
Number 100 will be 0100

But what I'm trying to achieve is:

Number 1 should be 0001
Number 10 should be 00010
Number 100 should be 000100
etc.

Is this possible? Hope you can help me.

Regards,

Danilo

3 Answers, 1 is accepted

Sort by
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 10 Jul 2015, 09:52 AM

Hi Danilo, I guess for this rather unusual formatting, your best option is to define an event handler to for the CellFormatting event.

 Regards

Erwin

0
Danilo
Top achievements
Rank 1
answered on 10 Jul 2015, 11:59 AM

Hi Erwin

The problem is, it's a DecimalColumn so it's deleting all 0 before the first "real" number.

Any other ideas? :)

Regards,
Danilo

0
Ralitsa
Telerik team
answered on 10 Jul 2015, 01:01 PM
Hi Danilo,

Thank you for contacting us. 

You can use the escape character to prevent the formatting operation. Here is the code snippet how to set the FormatString of GridViewDecimalColumn:
decimalColumn2.FormatString = "{0:\\0\\0\\0#}";

In the attachments you can find an image which demonstrates the result.  

You can refer to the following article from MSDN for more information about  Custom Numeric Format Strings, section "The Escape Character".
 
I hope this will help you. Let me know if you have any other questions.

Regards,
Ralitsa
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Danilo
Top achievements
Rank 1
Answers by
erwin
Top achievements
Rank 1
Veteran
Iron
Danilo
Top achievements
Rank 1
Ralitsa
Telerik team
Share this question
or