本文介绍了如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码示例:
private void comboBox_SelectedIndexChanged(object sender,EventArgs e)
{
if (某些条件)
{
comboBox.Text =new string
}
}
我的问题是comboBox文本总是显示选定的索引的字符串值,而不是新的字符串。
解决方案
这段代码应该可以工作...
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));
}
希望它有助于... :) / p>
Code example:
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if(some condition)
{
comboBox.Text = "new string"
}
}
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?
解决方案
This code should work...
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));
}
Hope it helps... :)
这篇关于如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!