Home Forums WinForms controls Xceed Grid for WinForms Formatting the currency fields for the grid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17402 |

    Hi,

    I’m trying to format the currency fields for my grid. The tricky part is that each row has a different currency. The first row should be in USD, and the second in CAD.

    I tried something like this:

    NumberFormatInfo nfi = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat;
    nfi.CurrencySymbol = “$”;
    myGrid.DataRows[0].Cells[“Price”].FormatProvider = nfi;

    nfi = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat;
    nfi.CurrencySymbol = “CAD”;
    myGrid.DataRows[1].Cells[“Price”].FormatProvider = nfi;

    The problem is that now both rows show CAD.

    What am I missing?

     

    thanx

    Imported from legacy forums. Posted by kozu (had 1615 views)

    Xceed Support
    Member
    Post count: 5658

     

    Hi Kozu,

    The instance you are using is static. Hence, it is using the last value that you set it to.

     

    Please use the following working sample as an example.

     

    Example:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Xceed.Grid.Editors;
    using Xceed.Grid.Viewers;
    using System.Globalization;

    namespace _26323
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                Xceed.Grid.Licenser.LicenseKey = “”;
                InitializeComponent();
                Xceed.Grid.Column columnPrice = new Xceed.Grid.Column(“Price”, typeof(Double));
                this.grid.Columns.Clear();
                this.grid.Columns.Add(columnPrice);

                Xceed.Grid.DataRow row0 = this.grid.DataRows.AddNew();
                row0.Cells[“Price”].Value = 10.025;
                row0.EndEdit();
                Xceed.Grid.DataRow row1 = this.grid.DataRows.AddNew();
                row1.Cells[“Price”].Value = 5.55;
                row1.EndEdit();

                NumberFormatInfo nfi = new NumberFormatInfo();
                nfi.CurrencySymbol = “$”;
                grid.DataRows[0].Cells[“Price”].FormatProvider = nfi;
                grid.DataRows[0].Cells[“Price”].FormatSpecifier = “C”;

                 NumberFormatInfo nfi1 = new NumberFormatInfo();
                nfi1.CurrencySymbol = “CAD”;
                grid.DataRows[1].Cells[“Price”].FormatProvider = nfi1;
                grid.DataRows[1].Cells[“Price”].FormatSpecifier = “C”;
            }
        }
    }

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1081 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.