|
-
Nov 22nd, 2005, 07:08 AM
#1
Thread Starter
Addicted Member
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
-
Nov 22nd, 2005, 07:11 AM
#2
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.
-
Nov 22nd, 2005, 07:13 AM
#3
Re: ComboBox questions
VBA question moved to Office Development.
-
Nov 22nd, 2005, 03:05 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|