Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUpdate ComboBox choices when the user enters a new choice
KeywordsComboBox, update ComboBox, update choices
CategoriesControls
 
When the user indicates the entry is finished, search the ComboBox's list of items. If the item is not there, add it.

How the user indicates an entry is finished depends on the program. This example assumes the user is done when focus moves out of the ComboBox.

 
' Save any new choice the user entered.
Private Sub cboInterest_LostFocus()
    UpdateCombo cboInterest
End Sub

Private Sub UpdateCombo(ByVal cbo As ComboBox)
Dim new_txt As String
Dim i As Integer
Dim found_it As Boolean

    ' See if the item is in the list.
    new_txt = cbo.Text
    found_it = False
    For i = 0 To cbo.ListCount - 1
        If new_txt = cbo.List(i) Then
            found_it = True
            Exit For
        End If
    Next i

    ' If the item is not in the list, add it.
    If Not found_it Then
        cbo.AddItem new_txt
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated