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

Formatting numeric data types

3 Answers 139 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Marek Kruk
Top achievements
Rank 1
Marek Kruk asked on 25 Apr 2012, 02:53 PM

Hello,

i want format numeric data in PropertyGrid - item.value and editor.value. 
For example:
value: 100000
formated value: 100 000

How can i do this? Can i use FormatString like "#,###"?

Greetings
Marek

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 30 Apr 2012, 12:10 PM
Hi Marek,

Thank you for writing.

Yes, you can format the text of both the visual item and the editor. Here is a sample application demonstrating how to achieve that:
    public Form1()
    {
        InitializeComponent();
        MyObject ob = new MyObject();
        ob.Number = 100000;
 
        radPropertyGrid1.SelectedObject = ob;
        radPropertyGrid1.ItemFormatting += new Telerik.WinControls.UI.PropertyGridItemFormattingEventHandler(radPropertyGrid1_ItemFormatting);
        radPropertyGrid1.EditorInitialized += new Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventHandler(radPropertyGrid1_EditorInitialized);
    }
 
    void radPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e)
    {
        PropertyGridSpinEditor editor = e.Editor as PropertyGridSpinEditor;
        if (editor != null)
        {
            editor.ThousandsSeparator = true;
        }
    }
 
    void radPropertyGrid1_ItemFormatting(object sender, Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs e)
    {
        if (e.Item.Name == "Number")
        {
            ((PropertyGridItemElement)e.VisualElement).ValueElement.Text = string.Format("{0:#,###}", ((PropertyGridItem)e.Item).Value);
        }
    }
}
 
class MyObject
{
    public int Number { get; set; }
}

Let me know if you have further questions.

Regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Marek Kruk
Top achievements
Rank 1
answered on 30 Apr 2012, 01:25 PM
Thank you for answer. Works great! :).
0
Stefan
Telerik team
answered on 03 May 2012, 01:09 PM
I am glad I could help Marek.

Should you have any other questions, do not hesitate to contact us.

Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
PropertyGrid
Asked by
Marek Kruk
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Marek Kruk
Top achievements
Rank 1
Share this question
or