|
-
Oct 15th, 2005, 04:40 AM
#1
Re-arrange list items [Resolved]
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..
Last edited by Atheist; Oct 15th, 2005 at 09:45 AM.
-
Oct 15th, 2005, 06:38 AM
#2
Re: Re-arrange list items
Randomly? I don't think so. You may resort listview by clicking on the column but that would only be ASC or DESC order.
-
Oct 15th, 2005, 06:55 AM
#3
Hyperactive Member
Re: Re-arrange list items
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
-
Oct 15th, 2005, 08:32 AM
#4
Addicted Member
Re: Re-arrange list items
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
-
Oct 15th, 2005, 08:52 AM
#5
Re: Re-arrange list items
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
-
Oct 15th, 2005, 09:29 AM
#6
Re: Re-arrange list items
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
-
Oct 15th, 2005, 09:35 AM
#7
Addicted Member
Re: Re-arrange list items
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
-
Oct 15th, 2005, 09:38 AM
#8
Re: Re-arrange list items
hey rhino i did the same thing but was getting error in this particular statement!
actually i was adding the items of listbox before actually finding the Random number like
VB Code:
For i = 0 To List1.ListCount - 1
arr(i) = List1.List(i)
List1.RemoveItem (i)
Next i
and it was deleting all the even indexed value!!!! why so???
-
Oct 15th, 2005, 09:39 AM
#9
Re: Re-arrange list items
You're not hijacking but rather suggesting ... Have you tried my sample yet?
-
Oct 15th, 2005, 09:44 AM
#10
Re: Re-arrange list items
 Originally Posted by Harsh Gupta
... and it was deleting all the even indexed value!!!! why so??? 
Because the minute you delete item ListCount changes ...
-
Oct 15th, 2005, 09:45 AM
#11
Re: Re-arrange list items
Yea i tried your code RhinoBull and it works perfect thank you
-
Oct 15th, 2005, 09:46 AM
#12
Re: Re-arrange list items
 Originally Posted by RhinoBull
Because the minute you delete item ListCount changes ...
ok........thnx very much rhino!!
-
Oct 15th, 2005, 09:52 AM
#13
Re: Re-arrange list items
 Originally Posted by Atheist
Yea i tried your code RhinoBull and it works perfect  thank you
Great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|