从源代码触发ComboBox的SelectionChangeCommitted事件

时间:2015-10-01 19:57:05

标签: c# events combobox event-handling selectionchanged

ComboBox.SelectedIndex将触发SelectedIndexChanged事件,有没有办法从代码触发ComboBox的SelectionChangeCommitted?

    public Form1()
    {
        InitializeComponent();
        string[] cb_items = { "A", "B", "C" };
        comboBox1.Items.AddRange(cb_items);
        comboBox1.SelectedIndex = 1;
        // what code will trigger comboBox_SelectionChangedCommitted from here?
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // triggered by comboBox1.SelectedIndex = 1
        textBox1.Text = "Selected " + comboBox1.SelectedItem;
    }

    private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
    {
        textBox1.Text = "Committed " + comboBox1.SelectedItem;
    }

1 个答案:

答案 0 :(得分:0)

Documentation读取:

  

“只有在用户时才会引发SelectionChangeCommitted事件   更改组合框选择...“

文件并不总是正确的,但没有相反的证据,我今天会相信它。