ComboBox cancel update from list

Posted by: kbj on 28 April 2018, 12:15 pm EST

    • Post Options:
    • Link

    Posted 28 April 2018, 12:15 pm EST

    Hi all,

    Is there a way to cancel the changing of the value property of a combobox when the user selects an item from the dropdown list?

    Thanks,

    Kingman

  • Posted 30 April 2018, 3:33 am EST

    Hi Kingman,

    From what I understand, you wish that when selecting a particular item from Combobox, the Value property should remain unchanged while the selection should still change in Combobox.

    If that is the case, then for that you first need to set TextDetached property to true and then inside ValueChanged event invoke the ValidateText method as follows:

    I have also attached a sample application for your reference.

    private void C1ComboBox4_ValueChanged(object sender, EventArgs e)
    {
         if(test_c1ComboBox.Value.ToString()=="c")
         {
              test_c1ComboBox.ValidateText();
         }
         Console.WriteLine($"Combobox's Value: {test_c1ComboBox.Value}");
    }
    

    Thanks,

    Ruchir AgarwalComboBox_Value.zip

  • Posted 30 April 2018, 8:03 am EST

    Hi Ruchir,

    Thanks for the quick response. What I am looking for is for the text property not to change when a user selects a certain list item. I would like the value to change.

    In the below example, selecting February would leave the Text as whatever it was, but change the Value to “February”

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    cb2.AutoCompleteMode = AutoCompleteMode.Suggest

    cb2.AutoCompleteSource = AutoCompleteSource.CustomSource

    cb2.Items.AddRange(New String() {“January”, “February”, “August”})

    cb2.AutoCompleteCustomSource.AddRange(New String() {

    “January”,

    “February”,

    “March”,

    “April”,

    “May”,

    “June”,

    “July”,

    “August”,

    “September”,

    “October”,

    “November”,

    “December”

    })

    End Sub

    Private Sub _ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cb2.ValueChanged

    If cb2.Value.ToString() = “February” Then

    cb2.DoSomethingThatWon’tChangeTheText()

    End If

    Console.WriteLine($“Combobox’s Value: {cb2.Value}”)

  • Posted 1 May 2018, 7:38 am EST

    Hi,

    Thank you for clarifying.

    However, I do not seem to find a direct solution for your requirement. So, if you could share your use-case as to why you need to change value but not the text, then probably I can help you achieve that using some workaround.

    Also, in addition to above, please mention your requirements with two aspects:

    1. When user types, suggestion appears and user selects an item: In this case, do you wish to show the selected item or the text that was typed.
    2. When user clicks dropdown button, dropdown opens and user selects an item: In this case, do you wish to show the selected item or the text that was typed.

    Thanks,

    Ruchir Agarwal

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels