How do you change the item that is selected in the list box control in code? I have tried setting the list.listindex but this doest work.
Printable View
How do you change the item that is selected in the list box control in code? I have tried setting the list.listindex but this doest work.
try:
List1.Selected(Index) = True
ROB
Regards,Code:Private Sub Form_Load()
With List1
.AddItem "This is a list box"
.AddItem "Please click on any item"
.AddItem "to change its value"
.AddItem "Hope this works"
End With
End Sub
Private Sub List1_Click()
Dim strNew As String
strNew = InputBox("Enter new item:", "New Item")
With List1
.List(.ListIndex) = strNew
End With
End Sub
TheBao
Code:Option Explicit
Private Sub Command1_Click()
'remember the index is 0 based so 5 = 6th item
List1.ListIndex = 5
MsgBox List1.Text
End Sub
Private Sub Form_Load()
'load up some junk
For x = 1 To 10
List1.AddItem x
Next x
List1.ListIndex = 0 '1st item is list
End Sub