在C#中以编程方式触发comboBox SelectedIndexChanged事件

Use*_*Mat 0 c# events combobox selectedindex selectedindexchanged

win表格上有一个组合框和一个按钮.如何通过单击按钮来激活comboBox selectedIndexChanged.

Ren*_*ogt 5

你应该重新考虑你的代码设计.看来你想提升事件来间接触发一些动作.为什么不这样试试呢:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     // do the things that should happen only if a real change happend
     // ...
     // then do the special thing you want
     DoTheOtherStuff();
}
private void button1_Clicked(object sender, EventArgs e)
{
    // do the things to happen when the button is clicked
    // ...
    // then do the special thing you want
    DoTheOtherStuff();
}
private void DoTheOtherStuff()
{
    // the special thing you want
}
Run Code Online (Sandbox Code Playgroud)

编辑:如果您的遗留代码与评论建议的一样尴尬,您仍然可以使用这种尴尬的方式:

private void button1_Clicked(object sender, EventArgs e)
{
    comboBox1_SelectedIndexChanged(comboBox1, EventArgs.Empty);
}
Run Code Online (Sandbox Code Playgroud)