TAGS :Viewed: 20 - Published at: a few seconds ago

[ how to change combobox (dropdownlist ) value with arrow key? ]

I have a combo box witch is DropDownList and i bind it to a property of a class. this Combo Box is populated with an array.

now in run time when i change selected item by mouse click every things sounds good. but when change item by arrow key any thing wont work. even textchanged event of combo box would not raise.

Answer 1


For ComboBoxit's really easy to use selected index changed event, instead of text changed event. It will fire by mouse or keyboard, when it changes the selection item of a ComboBox.

Example:

    private void CB_Company_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (CB_Company.SelectedItem.ToString() != "Select a company" & CB_Company.SelectedItem.ToString() != "")
        {
            CB_Company.BackColor = Color.White;
            CB_Company.Enabled = false;

            RB_Option1.Enabled = true;
            RB_Option2.Enabled = true;
        }
    }

Populating combobox method:

    private void SetDropDownItems()
    {
        List<DropDownModel> dropDownModel = new List<DropDownModel>();

        dropDownModel.Add(new DropDownModel()
        {
            Name = "Select a company",
            Value = ""
        });

        dropDownModel.Add(new DropDownModel()
        {
            Name = "My Company",
            Value = "Comp"
        });

        CB_Company.DataSource = dropDownModel;
        CB_Company.DisplayMember = "Name";
        CB_Company.ValueMember = "Value";
    }

I hope you get the idea.