Results 1 to 5 of 5

Thread: [RESOLVED] Check text entered in combobox against the dropdownlist genereated

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    76

    Resolved [RESOLVED] Check text entered in combobox against the dropdownlist genereated

    Hi,

    I have an windows mobile application. In the windows form of it, I have a combo box.
    I load the values in the combobox on frm_load event.
    Now we all know what the combo box has the facility that it allows to enter text as well as chose from the dropdown.
    So when they enter the text, I want to validate it against the list that is in it.
    If not then msbox error.

    Can you guide me with,how to validate.

    My loading of the combo box is here.

    Code:
    Private Sub mainfrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim con As New SqlConnection("XXXX")
            Try
                con.Open()
            Catch ex As Exception
                 'MsgBox("Problem in Connection with the SQL server")
        
            End Try
            Try
                
                ' filling the combobox with distinct bin numbers
                Dim cmd1 As New SqlCommand(" Select distinct Binnumber from [dbo].[bintable]", con)
                Dim rd1 As SqlDataReader = cmd1.ExecuteReader()
                While rd1.Read()
                    Barcode2.Items.Add(rd1(0).ToString)
                End While
            Catch ex As Exception
                MsgBox("Error loading the combo box with bin numbers.")
                con.Close()
            End Try
            Barcode1.Focus()
        End Sub

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Check text entered in combobox against the dropdownlist genereated

    Can you not just set the style to DropDownList so that they HAVE to select one from the list?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    76

    Re: Check text entered in combobox against the dropdownlist genereated

    I wish I could. If that was the case iwould have put a listbox or dropdown box, and not a combo box.
    Sorry Chris, its a requirement.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Check text entered in combobox against the dropdownlist genereated

    OK it was just a suggestion in case you were not aware of that property.

    As for validating the text against the items within the combobox, as it seems that you are just adding strings to the combobox you should just be able to do this:
    vb Code:
    1. If MyComboBox.Items.Contains(MyComboBox.Text) Then
    2.    'Valid input entered
    3. Else
    4.    'The text isnt in the list
    5. End If
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    76

    Re: Check text entered in combobox against the dropdownlist genereated

    Thanks. it worked perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width