Solved

Need help with Listview Comparer

Posted on 2014-04-28
7
397 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 39

Expert Comment

by:Kyle Abrahams
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 39

Expert Comment

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

Author Comment

by:Basicfarmer
Comment Utility
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 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
Perfect!!! Thank you...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now