Need help with Listview Comparer

Posted on 2014-04-28
Last Modified: 2014-04-28
Experts, I received some help previously on this topic for another project at Listview Comparer Help.

This worked fine for that particular project, but in a new project that i am working on it does not sort currency properly when there is a wide range of values.

In the attached screen shot i have show what it does with the currencies.

Screen Shot
Question by:Basicfarmer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40027720
It's comparing by a string rather than by decimal.  

Update your code to ignore the $.

string_x = item_x.SubItems(m_ColumnNumber).Text.Replace("$","")

string_y = item_y.SubItems(m_ColumnNumber).Text.Replace("$","")

Author Comment

ID: 40027764
I tried this and it does the same thing.
If Decimal.TryParse(Replace(string_x, "$", ""), flags, Nothing, dec_x) And Decimal.TryParse(Replace(string_y, "$", ""), flags, Nothing, dec_y) Then

Open in new window


Author Comment

ID: 40027805
With the code the way it was to start with, at the break point I can see that the value of dec_x and dec_y are in fact decimal values.
 Screen Shot
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40028058
Are you using a string format to set the currency?  What if you take that out?  Does it work?

Author Comment

ID: 40028090
I am using formatCurrency for the item in that column.
lstItem.SubItems.Add(FormatCurrency(reader.Item("IDTCost"), 2))

Open in new window

When i take it out it sorts properly.
I dont know why it is not working the way it is setup already. The TryParse is working using the flags and dec_x and dec_y are converted to decimal properly.
LVL 40

Accepted Solution

Kyle Abrahams earned 500 total points
ID: 40028283
Add this to your flags:

'... = the other globalizations you already have.  Add AllowThousands at the end.

flags = ... OR ... OR System.Globalization.NumberStyles.AllowThousands

Author Closing Comment

ID: 40028365
Perfect!!! Thank you...

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question