Re: Add item to Combo Box?
From: Jan Hyde (StellaDrinker_at_REMOVE.ME.uboot.com)
Date: 09/14/04
- Next message: Robert: "Re: Trap vbmaximum event."
- Previous message: Marissa: "Mr Randy Birch Help pls"
- In reply to: Milo: "Re: Add item to Combo Box?"
- Next in thread: Randy Birch: "Re: Add item to Combo Box?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 14 Sep 2004 09:05:59 +0100
Milo <Milo@Freenet.co.uk>'s wild thoughts were released on
Mon, 13 Sep 2004 17:09:53 +0100 bearing the following fruit:
>Jan Hyde wrote:
>> Milo <Milo@Freenet.co.uk>'s wild thoughts were released on
>> Mon, 13 Sep 2004 16:20:47 +0100 bearing the following fruit:
>>
>>
>>>Jan Hyde wrote:
>>>
>>>
>>>>"Damon" <nonsense@nononsense.com>'s wild thoughts were
>>>>released on Mon, 13 Sep 2004 14:13:54 GMT bearing the
>>>>following fruit:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>I am using VB6 and would like to be able to add an item to a combo box. I
>>>>>know that I can use the .additem but I need to be able to search the
>>>>>contents of the combo box to see if the value is already in there and if not
>>>>>add the item. I know there is Matchedtolist for a datacombo but how can I
>>>>>do this for a regular combo box?
>>>>>
>>>>>Would appreciate the help.
>>>>
>>>>
>>>>Use API calls
>>>>
>>>>http://vbnet.mvps.org/
>>>>
>>>>
>>>>
>>>>Jan Hyde (VB MVP)
>>>>
>>>
>>>use a loop, much easier than API.
>>
>>
>> Easier?!
>>
>>
>>> Dim bExist As Boolean
>>>
>>> bExist = False
>>>
>>> If Combo1.ListCount > 0 Then
>>> For i = 0 To Combo1.ListCount
>>
>>
>> Why not loop from 0 to Combo1.listcount -1 and save an
>> interation.
>>
>>
>>
>>> Combo1.ListIndex = i - 1
>>
>>
>> Then the above line isn't needed. The other reason the above
>> line could be very bad is that it fires the click event
>> which it turn could severely impare the performance of your
>> routine.
>>
>> J
>>
>>
>>> If Combo1.Text = Text1.Text Then '''change
>>>text1.text to additem source
>>> bExist = True
>>> End If
>>> Next i
>>> Else
>>> Combo1.AddItem Text1.Text '''change
>>>text1.text to additem source
>>> Exit Sub
>>> End If
>>>
>>> If bExist = False Then
>>> Combo1.AddItem Text1.Text '''change
>>>text1.text to additem source
>>> Else
>>> MsgBox "Item already in list!" '''add woteva
>>>happens here
>>> End If
>>>
>>>
>>>
>>>hope this helps....milo
>>
>>
>>
>> Jan Hyde (VB MVP)
>>
>come on guys, im only trying to help! at least it works! I think doing a
>loop like this is easier, well for the noobies anyway. Otherwise they
>have to learn the ways of the API. Unless they just wanna do a copy
>paste project.
>
>Oh well, nice to see a friendly environment!
>
Don't take my comments as critisism. See it as constructive
discusion. You must remember that these posts will be around
for years to come and pointing out any potential pitfalls
could save someone a lot of time in the future.
If I make a post for example, one of the other regulars may
follow it up with a comment that I'm fully aware of. They do
it not for my benefit but for the benefit of anyone else who
may read the thread.
This *is* a friendly environment and don't let my comments
put you of posting. We will comment on code that is posted
because it is a learning experience for all.
As far as APIs go, many are very simple to use. Randy's site
is a fantastic resource for beginners and experienced
programmers alike.
Don't take things too personally and enjoy the group.
Jan Hyde (VB MVP)
-- Uphill: Oral medication for adults (Stan Kegel) [Abolish the TV License - http://www.tvlicensing.biz/]
- Next message: Robert: "Re: Trap vbmaximum event."
- Previous message: Marissa: "Mr Randy Birch Help pls"
- In reply to: Milo: "Re: Add item to Combo Box?"
- Next in thread: Randy Birch: "Re: Add item to Combo Box?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|