Results 1 to 9 of 9

Thread: Mark the first item in my listbox when I load the form?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question Mark the first item in my listbox when I load the form?

    I always wanna mark the first item in my listbox when I start the form. How do I do that?

  2. #2
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    VB Code:
    1. Private Sub Form_Load()
    2.   List1.ListIndex = 0
    3. End Sub
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    VB Code:
    1. Private Sub Form_Load()
    2.     If List1.ListCount > 0 Then
    3.         List1.ListIndex = 0
    4.     End If
    5. End Sub

  4. #4
    Lively Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    70
    List1.Selected(0) = True

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    If I use List1.Selected(0) = True, the first item selected. But I still must click on the listbox to get the value to my code? Why?

  6. #6

  7. #7
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Call the click event of the list after you set the selected item

    VB Code:
    1. List1_Click
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  8. #8

  9. #9
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    which control are you using ??

    VB Code:
    1. Private Sub Form_Load()
    2.    List1.AddItem "hoera"
    3.    List1.Selected(0) = True
    4. End Sub
    5.  
    6. Private Sub List1_Click()
    7.   MsgBox "clicked"
    8. End Sub

    Worked for me without calling the click event.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

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