1

I have this code , i have search in the site how to format a column

listView2.Items.Clear();
listView2.GridLines = true;
        for (int i = 0; i < miraxy.Rows.Count; i++) 
            {
                DataRow drow = miraxy.Rows[i];

                if (drow.RowState != DataRowState.Deleted)
                {
                    ListViewItem lvi = new ListViewItem(drow["CFOP"].ToString());
                    lvi.SubItems.Add(drow["Tnota"].ToString());
                    lvi.SubItems.Add(drow["Valor"].ToString());
                    listView2.Items.Add(lvi);
                }
            }

i need to format the column "Valor" to 123.2456.789,2345 i have try with this code but don work .i need format to 2 decimal places.

   lvi.SubItems.Add( string.Format( "{0:000,000.00}",drow["Valor"].ToString()));

With this line :

     lvi.SubItems.Add( string.Format( "{0:000,000.00}", Convert.ToDecimal (drow["Valor"])));

i have this result : 1.419.192,67
001.528,41 how i need to write to kill the left zeros??

Thanks by any help

alejandro carnero
  • 1,774
  • 7
  • 27
  • 43

1 Answers1

0

Use this format string:

string.Format("{0:#,##0.00}", Convert.ToDecimal(drow["Valor"]))

The #'s (as opposite to 0) make that part of format used only, when the number is large enough.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992