Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

Need help with Listview Comparer

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
Basicfarmer
Asked:
Basicfarmer
  • 4
  • 3
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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
 
BasicfarmerAuthor Commented:
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
 
BasicfarmerAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Kyle AbrahamsSenior .Net DeveloperCommented:
Are you using a string format to set the currency?  What if you take that out?  Does it work?
0
 
BasicfarmerAuthor Commented:
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
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Add this to your flags:

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

flags = ... OR ... OR System.Globalization.NumberStyles.AllowThousands
0
 
BasicfarmerAuthor Commented:
Perfect!!! Thank you...
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now