Format a money value ListView Subitem as decimal and allow for nulls

I have a listview that I am populating from a data table.  The database field "Credit_Limit" is "money" type, and can contain null values.
The code below works -- nulls show nicely as an empty cell in the ListView, BUT "Credit_Limit" is shown like "500.0000" and I want it formated like "500.00"

What's the simplest way to add the ListView.SubItem formatted the way I want, an account for nulls?
Thanks!

foreach (DataRow row in myTable.Rows)
    {
        ListViewItem myListItem = new ListViewItem(row["Customer_Id"].ToString(), 1);
        myListItem.SubItems.Add(row["Cust_Name"].ToString());
        myListItem.SubItems.Add(row["Credit_Limit"].ToString());
        lstCustomers.Items.Add(myListItem);
     }

Open in new window

Rob RudloffIT Development SpecialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Luis PérezSoftware Architect in .NetCommented:
Try this:

myListItem.SubItems.Add(row["Credit_Limit"].ToString("#0.00"));

Hope that helps.
0
Rob RudloffIT Development SpecialistAuthor Commented:
Actually I originally tried that, since that's how I understood "ToString" to work ... but, I get the error:
"No overload for method 'ToString' takes 1 arguments"

0
Rob RudloffIT Development SpecialistAuthor Commented:
OK, it seems it can't be done in one step ... so --

To display nulls as empty cell:
     double DD;
     string SS;
     SS = (Double.TryParse(row["Credit_Limit"].ToString(), out DD) ? DD.ToString("0.00") : "");
     myListItem.SubItems.Add(SS);

Open in new window


To diplay nulls as 0:
     double DD;
     Double.TryParse(row["Credit_Limit"].ToString(), out DD);
     myListItem.SubItems.Add(DD.ToString("0.00"));

Open in new window


Just my best guess -- what is the "normal" way of doing this?
-- thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob RudloffIT Development SpecialistAuthor Commented:
this solution is the only one tht works
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.