Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppress Duplicate Items in a Combo box

Status
Not open for further replies.

tenbobmillionaire

Programmer
Jun 13, 2000
27
EU
Can anyone tell me how to stop an item appearing twice in a combo box? I want to skip the combobox.additem if the entry to be added already exists in the combo box. Is there a quick way to do this or is it a case of checking every item in the box every time you add an item?
Thanks
Mick
 
Assume the item you want to add is held in N$:

If (SendMessage(Combo1.hWnd, CB_FindStringExact, 0, N$) <> -1) Then Combo1.AddItem N$

For this to work, add these declarations:

Public Const CB_FindStringExact = &H158

Public Declare Function SendMessage Lib &quot;user32&quot; Alias &quot;SendMessageA&quot; (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

- Andy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top