如何更改comboBox.Text一个comboBox.SelectedIndexChanged事件中? [英] How do I Change comboBox.Text inside a comboBox.SelectedIndexChanged event?
本文介绍了如何更改comboBox.Text一个comboBox.SelectedIndexChanged事件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码示例:
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if(some condition)
{
comboBox.Text = "new string"
}
}
我的问题是对ComboBox文本始终显示所选指标的字符串值,而不是新的字符串。是一个解决方法呢?
My problem is that the comboBox text always shows the selected index's string value and not the new string. Is the a way round this?
推荐答案
此代码应工作...
public Form1()
{
InitializeComponent();
comboBox1.Items.AddRange(new String[] { "Item1", "Item2", "Item3" });
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
String text = "You selected: " + comboBox1.Text;
BeginInvoke(new Action(() => comboBox1.Text = text));
}
希望它可以帮助... :)
这篇关于如何更改comboBox.Text一个comboBox.SelectedIndexChanged事件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文