Listview control not sorting correctly, is it becuase it's a numer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm using vs2005, .net 2 for C# windows application.
One of my column on the Listview control has numericstring. Other columns
are sorting correctly except this one. It seems to be sorting the 1st
numeric char at the beging of the string. How do I resolve this problem?
Thank you?
 
You could implement the IComparer interface & use an ArrayList to store the
contents that are used to populate the ListBox, now pass the comparer when
using the Sort method.



public class MyComparer : IComparer
{
/*
Less than zero
x is less than y.

Zero
x equals y.

Greater than zero
x is greater than y.
*/

public int Compare(object x, object y)
{
int nx = Int32.Parse((string)x);
int ny = Int32.Parse((string)y);
return nx.CompareTo(ny);

}
}


I see that your listbox is a numeric string, so you can implement your custom
logic in the Compare method above.

-Arun
 
Thank you for the help but I don't know what do you mean by "pass the
comparer when using the Sort method"? ( I assume the Sort method of the
Listview is what is referred here). What am I doing with the arraylist? Do
I call the compare method to sort out the array?
Thanks.
 
Hi,
I have created a public class based on IComparer. But, I'm not able to
access the inherited public property "Order" to set the sorting order. When
I type the sortclss. I get no "Order" property in the drop down. How can I
set the sorting order of this sort class object? Thank you.
p.s. Other than the sort order, everyting else is working correctly
 
Ok, got that resovle. I added a public order property and it's working fine
now. Thank you very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top