Results 1 to 13 of 13

Thread: Re-arrange list items [Resolved]

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Talking 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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2

  3. #3
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    260

    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

  4. #4
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    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

  5. #5

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Re-arrange list items

    Well, listview is quite different from ordinary listbox...
    Anyway, try this sample:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     With List1
    5.         .AddItem "Item 1"
    6.         .AddItem "Item 2"
    7.         .AddItem "Item 3"
    8.         .AddItem "Item 4"
    9.         .AddItem "Item 5"
    10.     End With
    11. End Sub
    12.  
    13. Private Sub Command1_Click()
    14. Dim iIndex%, sItem$, i%
    15.  
    16.     Randomize
    17.    
    18.     With List1
    19.         For i = 0 To .ListCount - 1
    20.             iIndex = Int((.ListCount * Rnd) + 1)
    21.             sItem = .List((iIndex - 1))
    22.             .RemoveItem (iIndex - 1)
    23.             .AddItem sItem
    24.         Next i
    25.     End With
    26.  
    27. End Sub

  7. #7
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    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

  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Re-arrange list items

    VB Code:
    1. .RemoveItem (iIndex - 1)
    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:
    1. For i = 0 To List1.ListCount - 1
    2. arr(i) =  List1.List(i)
    3. List1.RemoveItem (i)
    4. Next i
    and it was deleting all the even indexed value!!!! why so???
    Show Appreciation. Rate Posts.

  9. #9

  10. #10

  11. #11

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Re-arrange list items

    Yea i tried your code RhinoBull and it works perfect thank you
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Re-arrange list items

    Quote Originally Posted by RhinoBull
    Because the minute you delete item ListCount changes ...
    ok........thnx very much rhino!!
    Show Appreciation. Rate Posts.

  13. #13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width