繁体   English   中英

在组合框中选择项目的事件

[英]event of selecting a item in combobox

我在窗体中有一个组合框和文本框(在Windows窗体平台中),默认情况下,可见的文本框为false,当要选择组合框的特定项时,我想显示该文本框。

组合框的哪个事件适合此工作!

如果您依靠组合框中的固定索引,则使用SelectedIndexChange事件

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == yourindex)
        textBox1.Visible = true; 
    else
        textBox1.Visible = false; 
}

如果您取决于组合框所选项目的值,请使用SelectedValueChanged事件

private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedValue.ToString() == "yourvalue")
        textBox1.Visible = true;
    else
        textBox1.Visible = false; 
}

使用组合框SelectedIndexChange事件或Selecton Change Committed,并在该事件中检查组合框的selectedValue

          if(combobox1.SelectedValue == desiredvalue)
               textBox1.Visible = true;

该准则肯定会为您提供帮助。

if (comboBox2.Text.ToString() == "Desired Value")
     comboBox1.Visible = true;
else
     comboBox1.Visible = false;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM