页面中有一个下拉列表和一个文本框,下拉列表中有 “早班”、“中班”、“晚班”要求如果选择“早班”文本框中显示“08:00”,选择“中班”文本框显示“16:00”晚班显示
“24:00”,这个应该怎么解决
combobox.Item.Add("早班");
combobox.Item.Add("中班");
combobox.Item.Add("晚班");
然后在combobox的SelectedIndexChanged事件中写显示代码
if(combobox.SelectedText == "早班")
{
textBox.Text = "08:00";
}
if(combobox.SelectedText == "中班")
{
textBox.Text = "16:00";
}
if(combobox.SelectedText == "晚班")
{
textBox.Text = "24:00";
}
在下拉列表值更新事件里写,string txt=this.combobox.text;
this.textbox.text=txt;
重新贴一下,已验证。
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("早班");
comboBox1.Items.Add("中班");
comboBox1.Items.Add("晚班");
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text.Equals("早班"))
{
textBox1.Text = "08:00";
}
if (comboBox1.Text.Equals("中班"))
{
textBox1.Text = "16:00";
}
if (comboBox1.Text.Equals("晚班"))
{
textBox1.Text = "24:00";
}
}