Stack Exchange
Format Column in ListViewBox as Currency
im trying to Format Arr1 in my code as currecny but it's not playing nice (translation = NOT WORKING) in my Ammount's column
Here is my block of code; 
       public void TransactionLog()
       {

        listView1.View = View.Details;
        listView1.GridLines = true;
        listView1.FullRowSelect = true;

        listView1.Columns.Add("Buy/Sell", 97);
        listView1.Columns.Add("Amount", 95);
        listView1.Columns.Add("Transaction ID", 100);

        string[] arr = new string[3];
        ListViewItem item;

        string URT = "https://api.eveonline.com/char/WalletTransactions.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH";
        XmlDocument XMLtrans = new XmlDocument();
        XMLtrans.Load(URT);
        XmlNodeList TRnodelist = XMLtrans.SelectNodes("/eveapi/result/rowset/row");
        foreach (XmlNode xmlnode in TRnodelist)
        {
            if (xmlnode.Attributes["transactionType"] != null)
                arr[0] = xmlnode.Attributes["transactionType"].InnerText;
            if (xmlnode.Attributes["price"] != null)
                arr[1] = xmlnode.Attributes["price"].InnerText;
            if (xmlnode.Attributes["transactionID"] != null)
                arr[2] = xmlnode.Attributes["transactionID"].InnerText;
            item = new ListViewItem(arr);
            listView1.Items.Add(item);     
        }

I've tried;
string.Format(CultureInfo.CreateSpecificCulture("ja-JP"), "{C:0}",  arr[1] = xmlnode.Attributes["price"].InnerText);

but im just getting errors.


What do you mean by not play nice exactly? What you get as a result and what do you want to get it exactly? Can you please give as examples?

well i want to format my Price column as a currency.

Replace {C:0} with {0:C}. That's all I see is wrong in your code, looks like a simple typo.

actually i take that back it's not working .

@Losec I updated my answer, Please check it.

As bokibeg commented, String.Format uses the composite formatting feature. Here it's syntax;
{index[,alignment][:formatString]}

As you can see, index component comes before the string component.
Other thing is, The "C" format specifier is for numeric values. That means, you can't format a string with that.
If your xmlnode.Attributes["price"].InnerText returns some valid numeric value, you can parse it with proper type Parse method before you try to format it. For example, if this returns valid int, you need use int.Parse() before you format it.
string.Format(CultureInfo.CreateSpecificCulture("ja-JP"), 
              "{C:0}",
              int.Parse(xmlnode.Attributes["price"].InnerText));


getting na unhandled exception.

@Losec What xmlnode.Attributes["price"].InnerText returns exactly?

im using this link https://api.eveonline.com/char/WalletTransactions.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH and the XML field "Prices"

or the error that im getting says " {"Input string was not in a correct format."} "

@Losec No, what is the value of ``InnerText` property exactly? Debug your code and check it.

well it returns multiple values? unless im misunderstanding what you mean? the first value it returns is 498998.84

@Losec If this is the value that you want to format, then you need to get this value first. Then parse it to double with double.Parse then you can format it. I have no idea how this InnerText returns multiple values but you need to get the real value that you want to format.

ok i've just edited my main question including the full block of code for my listviewbox, it scanns the XML file from the link and where "prices" are with in the elements it's returning them attributes. i've also included a picture.

You must replace {C:0} with {0:C}
 string.Format(CultureInfo.CreateSpecificCulture("ja-JP"), "{0:C}",  arr[1] = xmlnode.Attributes["price"].InnerText);


this hasen't worked, getting no formatting for my column
