ListView Sort by Number, why not?

gcollins

Guest
Joined
Sep 13, 2006
Messages
31
Location
Port Hope
Programming Experience
Beginner
If I have a list of files labled by number windows shows them in the right order. How come this doesn't work for ListView?

ex.

1 to 19

List view goes like this:

1 10 11 12 13 14 15 16 17 18 19 2 3 4 5 6 7 8 9

I know it's because 10 to 19 begin with 1, but is there a way to change this and go in the order from 1 to 19.

I want to use LargeIcon for this but they are all out of whack.

Or do I have to right a bunch of code to fix this?

Have a look:

image.jpg


Also if someone can tell me how to change the size of the labels and spacing in between the icons that would be very helpful to. :)

Thanks
 
Last edited:
Hello,
i would use an arrayList object to add the numbers in a range between 1 and 19 and then would use the Sort() method of the arrayList ... now you can add safety the values to the listview in wanted order.
However that's what i would do .. maybe someone else has a better idea.
Regards ;)
 
Let me explain what I am trying to do better.

What I have is a tree view that displays directories when a user clicks on the folder the contents are displayed in the listview, a folder can have items numbered from 1-19 but a few folders down the files may start 77 to 116.

I see all sorts of examples on how to sort when clicking on a column header (still got to figure those out) but what if you are in LargeIcon view?

With what you said would that still work for me and could you give me an example.

I'm new just started .net a couple of weeks ago.

Thanks
 
Sort an ArrayList and pass the values to the listview control

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myList [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ArrayList = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ArrayList
myList.Add(1)
myList.Add(10)
myList.Add(11)
myList.Add(12)
myList.Add(13)
myList.Add(14)
myList.Add(15)
myList.Add(16)
myList.Add(17)
myList.Add(18)
myList.Add(19)
myList.Add(2)
myList.Add(3)
myList.Add(4)
myList.Add(5)
myList.Add(6)
myList.Add(7)
myList.Add(8)
myList.Add(9)
myList.Add(77)
myList.Add(78)
myList.Add(116)
myList.Add(115)
 
[/SIZE][SIZE=2][COLOR=#008000]'use ArrayList's Sort method 
[/COLOR][/SIZE][SIZE=2]myList.Sort()
 

[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] myList.Count - 1
[/SIZE][SIZE=2][COLOR=#0000ff]  Dim[/COLOR][/SIZE][SIZE=2] lvitem [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ListViewItem = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListView1.Items.Add(myList.Item(i), 0)
[/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'uncoment code below if you prefer to use an Enumerator 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'Dim en As IEnumerator = myList.GetEnumerator
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'While en.MoveNext
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'   Dim lvitem As ListViewItem = Me.ListView1.Items.Add(en.Current, 0)
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'End While
[/COLOR][/SIZE]

HTH
Regards ;)
 

Attachments

  • sorting.png
    sorting.png
    11.9 KB · Views: 36
Back
Top