RadGridView Thousands Separator for Decimal Column While Editing

660 Views Asked by At

I can add thousands separator for my decimal column like this:

var decimalColumn = radGridView1.Columns["DecimalColumn"] as GridViewDecimalColumn;
decimalColumn.ThousandsSeparator = true;
decimalColumn.FormatString = "{0:n0}";

It works fine. But When I'm in editing mode and I type for example 1000000 then will be not thousands separator while editing. So the user may be confused.

How to apply thousands separator to a decimal column while editing? Is there any built-in feature?

1

There are 1 best solutions below

3
Dess On

If you want to show a thousands separator, indeed, it is appropriate to set the column's ThousandsSeparator property to true. This is expected to affect the editor as well.

However, RadGridView gives you access to the editor in the CellEditorInitialized event. Hence, you can enable it explicitly for the editor:

        public RadForm1()
    {
        InitializeComponent();

        GridViewDecimalColumn decimalColumn = radGridView1.Columns["UnitPrice"] as GridViewDecimalColumn;
        decimalColumn.ThousandsSeparator = true;
        decimalColumn.FormatString = "{0:n0}"; 

        this.radGridView1.CellEditorInitialized += RadGridView1_CellEditorInitialized;
    }

    private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        GridSpinEditor spinEditor = e.ActiveEditor as GridSpinEditor;
        if (spinEditor!=null)
        {
            spinEditor.ThousandsSeparator = true;
        }
    }

enter image description here

I hope this information helps.