Option Explicit On 
Option Strict On

Public Class frmCombo
  Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub
  Friend WithEvents cboExample As System.Windows.Forms.ComboBox
  Friend WithEvents btnProcess As System.Windows.Forms.Button

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.Container

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.btnProcess = New System.Windows.Forms.Button()
    Me.cboExample = New System.Windows.Forms.ComboBox()
    Me.SuspendLayout()
    '
    'btnProcess
    '
    Me.btnProcess.Location = New System.Drawing.Point(72, 176)
    Me.btnProcess.Name = "btnProcess"
    Me.btnProcess.Size = New System.Drawing.Size(136, 23)
    Me.btnProcess.TabIndex = 1
    Me.btnProcess.Text = "&Process Choice"
    '
    'cboExample
    '
    Me.cboExample.DropDownStyle = System.Windows.Forms.ComboBoxStyle.Simple
    Me.cboExample.DropDownWidth = 216
    Me.cboExample.Location = New System.Drawing.Point(32, 8)
    Me.cboExample.Name = "cboExample"
    Me.cboExample.Size = New System.Drawing.Size(216, 150)
    Me.cboExample.Sorted = True
    Me.cboExample.TabIndex = 0
    '
    'frmCombo
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(302, 231)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnProcess, Me.cboExample})
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Name = "frmCombo"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Combo Box Problem"
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private Sub cboExample_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboExample.KeyPress
    'when entered clicked, check entry
    If e.KeyChar = ControlChars.Cr Then
      btnProcess.PerformClick()
    End If
  End Sub

  Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
    Dim I As Integer
    'If in list - exit procedure
    If cboExample.Items.Count <> 0 Then
      For I = 0 To cboExample.Items.Count - 1
        If cboExample.Text = CStr(cboExample.Items(I)) Then
          Exit Sub
        End If
      Next I
    End If
    'If not found, add to list box
    cboExample.Items.Add(cboExample.Text)
  End Sub



  Private Sub frmCombo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Add a few words to start with
    cboExample.Items.Add("Visual Basic")
    cboExample.Items.Add("Combo Box")
    cboExample.Items.Add("Programmer")
    cboExample.Items.Add("Class 3")
    cboExample.Items.Add("List Box Control")
    cboExample.Items.Add("Event-driven")
  End Sub


End Class
