Results 1 to 9 of 9

Thread: Moving list Items up and down

  1. #1

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    This is a bit foolish question bu I forgot how to do it.
    I want to move items listed in the list box up or down. How do I do it?

    Kinjal

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Private Sub Form_Load()
     For n = 0 To 10
      List1.AddItem n
     Next n
    End Sub
    
    Private Sub List1_Click()
     List1.AddItem List1.List(List1.ListIndex), 1
     List1.RemoveItem List1.List(List1.ListIndex + 1)
    End Sub
    Havent tested it yet but see if it works
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    The items are already added to the list box and I wan to change their position i.e move the entries up or down using command buttons.

  4. #4

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535

    Unhappy

    No Kedaman it's not working. The program shows error whenever I click the list box.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    what error? where?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Member
    Join Date
    May 2000
    Posts
    63
    This seems to work. Create a new form with a listbox, and two command buttons. cmdUp and cmdDown. When the user highlights an item in the list, then clicks the up or down button, the highlighted item will move up or down...

    Private Sub cmddown_Click()
    Dim ts As String
    Dim tindex As Integer

    tindex = List1.ListIndex
    If tindex < List1.ListCount - 1 Then
    ts = List1.List(tindex + 1)
    List1.List(tindex + 1) = List1.List(tindex)
    List1.List(tindex) = ts
    List1.ListIndex = tindex + 1
    End If

    End Sub

    Private Sub cmdup_Click()
    Dim ts As String
    Dim tindex As Integer

    tindex = List1.ListIndex
    If tindex > 0 Then
    ts = List1.List(tindex - 1)
    List1.List(tindex - 1) = List1.List(tindex)
    List1.List(tindex) = ts
    List1.ListIndex = tindex - 1
    End If

    End Sub

    Private Sub Form_Load()
    Dim i As Integer

    For i = 1 To 10
    Me.List1.AddItem Str(i)
    Next

    End Sub

  7. #7
    Guest
    perfect.... thank you,
    I needed this code too

  8. #8

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535

    Talking

    Thanks a lot jmatello.

    Kinjal

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yeas, thank you, i was after this too

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