...

View Full Version : Visual Basic list box



cooleo100d
02-12-2005, 03:24 AM
Hi,

I'm using visual basic 6. I have a list box, and I add some items to it like this:


list.AddItem "Item 1", 0
list.AddItem "Item 2", 1
list.AddItem "Item 3", 2


Then I have a button, and I want it so when the user clicks the button, I want the item thats selected to move up in position 1 slot. I tried something like this:


list.ListIndex = list.ListIndex - 1

But that just changes the selection bar thing, and not the position of the item.

How would I go about doing this?

Thanks for your help,
~David

Kurt@BInvisions
02-12-2005, 05:48 AM
Give this a try.



Private Sub cmdDown_Click()
Dim Temp As String
With List1
If .ListIndex < .ListCount - 1 And .ListIndex >= 0 Then
Temp = .List(.ListIndex)
.List(.ListIndex) = .List(.ListIndex + 1)
.List(.ListIndex + 1) = Temp
.ListIndex = .ListIndex + 1
End If
End With
End Sub

Private Sub cmdUp_Click()
Dim Temp As String
With List1
If .ListIndex > 0 Then
Temp = .List(.ListIndex)
.List(.ListIndex) = .List(.ListIndex - 1)
.List(.ListIndex - 1) = Temp
.ListIndex = .ListIndex - 1
End If
End With
End Sub

cooleo100d
02-12-2005, 05:57 AM
Hi,

It works perfectly. You just have to change the With List1 to with list.

Thanks sooo much for your help,
~David



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum