change NumberDecimalSeparator in grid

9 posts, 0 answers
  1. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 14 Jun Link to this post

    hello

    i want change NumberDecimalSeparator  to grid example below:

    120.459->120/459

  2. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 14 Jun Link to this post

    1- i use format string:"{0:#/000}" but have problem:

    0.123  -> /123

    2- i need to active ThousandsSeparator

    1234.567 - >  1,234.456

  3. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 14 Jun Link to this post

    excuseme

    3-if value is 0 i want show 0

    4- if value not float number not show any float number 123.000-> 123

  4. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 18 Jun Link to this post

    hi

    please help me

  5. Nadya
    Admin
    Nadya avatar
    42 posts

    Posted 18 Jun Link to this post

    Hello, Moj,

    According to the provided information, it seems that the desired number formats are quite different. Indeed, you can use GridViewDecimalColumn which allows decimal data to be displayed and edited in RadGridView, as you have already found out. To cover all your specific needs you can also use  GridViewMaskBoxColumn and set a mask to the GridViewMaskBoxColumn using its Mask and MaskType properties. 

    First, if you need to change decimal separator with "/", you can go to your computer's settings, following this path: "Windows Control Panel | Region | Formats | Additional settings | Numbers" (this is the path in Windows 10 and it may be different for other Windows versions, but the principle is the same) and then change your current decimal symbol with the specified one, e.g. "/". Please, keep in mind that this will affect all your Windows settings.

    Another way is to use the CultureInfo class and initialize a new instance of the NumberFormatInfo class to implement your own specific logic. This approach is demonstrated in the following code snippet:

    CultureInfo c = new System.Globalization.CultureInfo("en-EN");
    NumberFormatInfo nfi = new NumberFormatInfo();
    nfi.NumberDecimalSeparator = "/";
    c.NumberFormat = nfi;
    System.Threading.Thread.CurrentThread.CurrentCulture = c;

    Following your specific needs, described below, I can suggest to use the CellFormatting event, which allows the content of data cell to be formatted in a specific way to display. Please refer to the following code snippet which covers your cases. Feel free to modify it in a way which suits your requirements best.



    public partial class Form1 : RadForm
    {
        public Form1()
        {
            InitializeComponent();
     
            CultureInfo c = new System.Globalization.CultureInfo("en-EN");
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalSeparator = "/";
            c.NumberFormat = nfi;
            System.Threading.Thread.CurrentThread.CurrentCulture = c;
     
            GridViewMaskBoxColumn maskBox = new GridViewMaskBoxColumn();
            maskBox.MaskType = MaskType.Numeric;
            maskBox.HeaderText = "MaskBoxColumn"
            maskBox.TextAlignment = ContentAlignment.BottomRight;
            maskBox.Width = 150;
            maskBox.DataType = typeof(decimal);
            radGridView1.MasterTemplate.Columns.Add(maskBox);
     
             
            this.radGridView1.Rows.Add(123.1234);
            this.radGridView1.Rows.Add(0.1234);
            this.radGridView1.Rows.Add(1234.567);
            this.radGridView1.Rows.Add(0);
            this.radGridView1.Rows.Add(123.000);
     
            this.radGridView1.CellFormatting += RadGridView1_CellFormatting;
        }
     
        decimal parsedValue = 0;
        private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement.Value != null && decimal.TryParse(e.CellElement.Value.ToString(), out parsedValue))
            {
                if (parsedValue == 0)
                {
                    e.CellElement.Text = "0";
                }
                else if (e.CellElement.Value.ToString().StartsWith("0"))
                {
                    e.CellElement.Text = e.CellElement.Value.ToString().Substring(1);
                }
                else if (parsedValue > 999)
                {
                    e.CellElement.Text = parsedValue.ToString("N");
                }
            }
        }
    }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Nadya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  6. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 22 Jun in reply to Nadya Link to this post

    Hello

    Very thanks for reply

    I need sort column by numeric but in GridViewMaskBoxColumn sort column by string.

  7. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 22 Jun in reply to moj Link to this post

    Hello

    I solve My problem for "/" with following code:

    CultureInfo PersianCultureInfo = new System.Globalization.CultureInfo("fa-IR");
    NumberFormatInfo nfi = new NumberFormatInfo();
    nfi.NumberDecimalSeparator = "/";
    PersianCultureInfo.NumberFormat = nfi;
    System.Threading.Thread.CurrentThread.CurrentCulture = PersianCultureInfo;
     
    this.gridViewDecimalColumn3.DecimalPlaces = 3;
    this.gridViewDecimalColumn3.FormatInfo = PersianCultureInfo;
    this.gridViewDecimalColumn3.FormatString = "{0:#,0.000}";

     

    I have 1 question, how  remove float number if it is zero similar  123/000 -> 123

  8. Nadya
    Admin
    Nadya avatar
    42 posts

    Posted 24 Jun Link to this post

    Hello Moj,

    To achieve a result with no zeros after the decimal separator you can use the CellFormatting event: 
    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.Value != null )
        {
            decimal value = (decimal)e.CellElement.Value;
            
            bool isInt = value % 1 == 0;
            if (isInt)
            {
                e.CellElement.Text = ((int)value).ToString();
            }
        }
    }

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

    Regards,
    Nadya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  9. moj
    moj avatar
    11 posts
    Member since:
    Jun 2019

    Posted 25 Jun Link to this post

    Hello, Nadya

    Very thanks

Back to Top