Results 1 to 4 of 4

Thread: ComboBox questions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195

    ComboBox questions

    I have a few questions regarding the ComboBox in VBA. Each item in the list has a unique key, and I want to use this to set the initial selected item in the combo. How would I do this? Obviously the following line of code won't work, but it ought to give a good idea of what I'm trying to do:

    Code:
    cboNameList.SelectedKey = "#12"
    Something like that, which'd select whichever item has the key '#12'. Is this possible?

    Thanks
    Using Visual Studio .NET 2005

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: ComboBox questions

    I think you're going to have to loop through the combo's list looking for the key then do something like cboNameList.List(i).Selected = True (not sure about the syntax - I'm typing this from memory)
    This world is not my home. I'm just passing through.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox questions

    VBA question moved to Office Development.

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: ComboBox questions

    If the key is actually the Key property a la VB6 (listview etc), then you can just refer to it like you would an index:

    Combobox1.listitems("itemkey1").text

    or something of the sort.
    However, I think that's only the case if you add in the Windows controls - the normal combobox works in the same way as a listbox, using the Additem method. Here, each item doesn't have a key property. So if it is something that you've set yourself, then you may have to be a bit more specific as to what you mean by "key". Do you just mean that the text of the item is unique?

    zaza

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