c# comboBox1.Items 修改

来源:百度知道 编辑:UC知道 时间:2024/05/25 20:48:38
有个comboBox1 前面有两个radiobutton 我想通过不同的选择 让comboBox1下拉选项不一样 可以做到吗?

分别在两个radioButton的radioButton_CheckedChanged事件中写如下代码:
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
this.comboBox1.Items.Clear();
if (this.radioButton1.Checked)
{
this.comboBox1.Items.Add("1");
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
this.comboBox1.Items.Clear();
if (this.radioButton2.Checked)
{
this.comboBox1.Items.Add("2");
}
}