gd day gents.
This will be hard to explain with my bad english...
Is there any way to "re-arrange" the order of a lists items?
I would like them to be randomly re-arranged..
Printable View
gd day gents.
This will be hard to explain with my bad english...
Is there any way to "re-arrange" the order of a lists items?
I would like them to be randomly re-arranged..
Randomly? I don't think so. You may resort listview by clicking on the column but that would only be ASC or DESC order.
Hi Atheist
may it can be done . but befor that i have to understand how exaclty u want to reaarange list items. could u provide ur code or give some better explanation
regards
shivpreet2k1
Yeah, it most surtanly can be done, but please elaborate a bit more :) It kinda depends on how big the list is and so on
Hello :)
What ive got is just a simple Listbox. It can only hold up to 23 entries.
And what I would like is when I press a command button, all the list items should be randomly re-arranged.
Cheers
Well, listview is quite different from ordinary listbox...
Anyway, try this sample:
VB Code:
Option Explicit Private Sub Form_Load() With List1 .AddItem "Item 1" .AddItem "Item 2" .AddItem "Item 3" .AddItem "Item 4" .AddItem "Item 5" End With End Sub Private Sub Command1_Click() Dim iIndex%, sItem$, i% Randomize With List1 For i = 0 To .ListCount - 1 iIndex = Int((.ListCount * Rnd) + 1) sItem = .List((iIndex - 1)) .RemoveItem (iIndex - 1) .AddItem sItem Next i End With End Sub
Don't wanna hijack the thread, but if you wanted to do the same with a listbox with only 23 items, I guess you would just pull the items out of the box, randomize and put em back? Make an array I mean
hey rhino i did the same thing but was getting error in this particular statement!VB Code:
.RemoveItem (iIndex - 1)
actually i was adding the items of listbox before actually finding the Random number likeand it was deleting all the even indexed value!!!! why so??? :confused: :(VB Code:
For i = 0 To List1.ListCount - 1 arr(i) = List1.List(i) List1.RemoveItem (i) Next i
You're not hijacking but rather suggesting ... Have you tried my sample yet?
Because the minute you delete item ListCount changes ...Quote:
Originally Posted by Harsh Gupta
Yea i tried your code RhinoBull and it works perfect :bigyello: thank you
ok........thnx very much rhino!!Quote:
Originally Posted by RhinoBull
Great! :wave:Quote:
Originally Posted by Atheist