Solved

Need help with Listview Comparer

Posted on 2014-04-28
7
400 Views
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
0
Comment
Question by:Basicfarmer
  • 4
  • 3
7 Comments
 
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("$","")
0
 

Author Comment

by:Basicfarmer
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

0
 

Author Comment

by:Basicfarmer
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
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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?
0
 

Author Comment

by:Basicfarmer
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.
0
 
LVL 40

Accepted Solution

by:
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
0
 

Author Closing Comment

by:Basicfarmer
ID: 40028365
Perfect!!! Thank you...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

770 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