Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Highlighting first item in a combo box

    I'm using Office 97. I created a combo box in VB for Word that works just fine. However, I'd like to have the first item in the combo box come up 'highlighted' as a selection. I know I've seen this in various dialog boxes; I just can't make it happen in mine. I suspect it needs to be set somewhere in the Properties for the object. Can anyone help me out?

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Highlighting first item in a combo box

    Hi,
    I think the line Me.ComboBoxNameHere.ListIndex = 0 should set it to the first value in your list.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlighting first item in a combo box

    Thanks for your quick reply. I realize I probably should have included the code for the object, which I do now. It's a dual combo box, and I do have the "...ListIndex" set to 0 in each case. That seems only to make the first item in the list appear in the combo box when it displays, but not to have that first item appear selected.

    Here's the code:
    Private Sub Userform_Initialize()

    cmbBef.AddItem "0"
    cmbBef.AddItem "2"
    cmbBef.AddItem "4"
    cmbBef.AddItem "6"
    cmbBef.AddItem "8"
    cmbBef.AddItem "12"
    cmbAft.AddItem "0"
    cmbAft.AddItem "2"
    cmbAft.AddItem "4"
    cmbAft.AddItem "6"
    cmbAft.AddItem "8"
    cmbAft.AddItem "12"

    cmbBef.ListIndex = 0
    cmbAft.ListIndex = 0

    End Sub

  4. #4
    calacuccia
    Guest

    Re: Highlighting first item in a combo box

    You should set the style property of the combo boxes to fmStyleDropDownList (2) manually or do this in your initialisation

    Private Sub Userform_Initialize()
    cmbBef.Style = fmStyleDropDownList
    cmbAft.Style = fmStyleDropDownList
    cmbBef.AddItem "0"
    cmbBef.AddItem "2"
    cmbBef.AddItem "4"
    cmbBef.AddItem "6"
    cmbBef.AddItem "8"
    cmbBef.AddItem "12"
    cmbAft.AddItem "0"
    cmbAft.AddItem "2"
    cmbAft.AddItem "4"
    cmbAft.AddItem "6"
    cmbAft.AddItem "8"
    cmbAft.AddItem "12"

    cmbBef.ListIndex = 0
    cmbAft.ListIndex = 0

    End Sub

  5. #5
    New Lounger
    Join Date
    Jan 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlighting first item in a combo box

    Works like a charm! thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •