Results 1 to 4 of 4

Thread: List Box Control

  1. #1
    lord_dude
    Guest

    Question

    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.

  2. #2
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575
    try:

    List1.Selected(Index) = True

    ROB

  3. #3
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    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
    Regards,
    TheBao

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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