Formatting numeric data types

4 posts, 1 answers
  1. Marek Kruk
    Marek Kruk avatar
    16 posts
    Member since:
    Mar 2009

    Posted 25 Apr 2012 Link to this post

    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

  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 30 Apr 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Marek Kruk
    Marek Kruk avatar
    16 posts
    Member since:
    Mar 2009

    Posted 30 Apr 2012 Link to this post

    Thank you for answer. Works great! :).
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 03 May 2012 Link to this post

    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 >>
Back to Top