ComboBox Selected Value changes when typed into

Posted on 2009-04-18
Last Modified: 2012-05-06
I have a combobox that allows users to create a new record and/or select a record and rename it through the combobox.
I also allow them to duplicate a record and then just rename it.
When they type into the combobox, there no longer is a selectedvalue.
How do I programmatically set when the combobox will hold it's selection?
Question by:Sheritlw
    LVL 39

    Expert Comment

    Not sure if I understand what you mean. Do you try to prevent people from selecting by typing, or do you want to allow them to select by typing when the focus is on the combobox?

    Author Comment

    No I want them to be able to Change the ComboText of an item selected from that combo only under certain circumstances.  When they change the text of a selected item to change the name, it loses the selectedvalue.
    LVL 39

    Accepted Solution

    When a user types into the edit section of a dropdown control, the control sends a TextUpdate event. With first change, i.e., with the first letter that a user types, the TextUpdate event is fired and the SelectedItem is still set valid and set. So what you can do inside the TextUpdate event is for instance:

        Private Sub ComboBox1_TextUpdate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.TextUpdate
            If ComboBox1.SelectedIndex = 3 Then
                MessageBox.Show("Sorry, not allowed")
                ComboBox1.Text = ComboBox1.SelectedItem
            End If
        End Sub

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now