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

Formatting GridViewDecimalColumn

3 Answers 847 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Curtis
Top achievements
Rank 2
Curtis asked on 19 Oct 2011, 04:25 PM
Hey there,

I was wondering how to go about formatting a value within a DecimalColumn. When creating the column, I set decimal places to 5:

decimalBoxColumn = New GridViewDecimalColumn
decimalBoxColumn.DataType = GetType(Decimal)
decimalBoxColumn.Name = "Quantity"
decimalBoxColumn.FieldName = "Quantity"
decimalBoxColumn.AllowSort = False
decimalBoxColumn.TextAlignment = ContentAlignment.MiddleRight
decimalBoxColumn.DecimalPlaces = 5
decimalBoxColumn.HeaderText = "Quantity"
decimalBoxColumn.HeaderTextAlignment = ContentAlignment.MiddleRight
decimalBoxColumn.MaxWidth = 100
BomRadGridView.MasterTemplate.Columns.Add(decimalBoxColumn)

When using the spin edit controls to modify the value, everything stays formatted correctly (the displayed value contains five decimal places). However, if the user types a value into the spin edit (rather than using the up and down arrows), the value will stay exactly as they input - it will not format it to the five decimal display. So if a user types 2.5, that value sticks in there. Is there a way so that if the user enters 2.5, when they leave the cell it will be formatted to 2.50000?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 20 Oct 2011, 10:11 AM
Hello Thabani,

Thank you for your question. 

You can achieve the desired behavior by setting the FormatString property of the column. Here is how to achieve it:
decimalBoxColumn.FormatString = "{0:F5}";

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
Best wishes,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Curtis
Top achievements
Rank 2
answered on 20 Oct 2011, 03:01 PM
Works beautifully. I explored the FormatString property, however I wasn't utilizing it correctly. Thanks a million!
0
Stefan
Telerik team
answered on 21 Oct 2011, 01:37 PM
Hello Thabani,

I am glad that I could help. Should you have any other questions, do not hesitate to contact us.
 
Regards,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
GridView
Asked by
Curtis
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Curtis
Top achievements
Rank 2
Share this question
or