【发布时间】:2013-12-23 11:35:43
【问题描述】:
我需要一点帮助。我有一个名为Form1 的主表单。
当我单击按钮btn1 时,会出现一个名为Form2 的新表单。
在Form2 中,我有几个文本框和一个名为cb2 的组合框。
对于TextBoxes,我是这样设置显示文本的:
//on Form1 I have this code
private void btn1_Click(object sender, EventArgs e)
{
Form2 form2= new Form2();
string a = "Text to be displayed in a textBox";
form2.txtMyTextBox = a;
form2.Owner = this;
form2.ShowDialog(this);
}
//on Form2 I set Public String
public string txtMyTextBox
{
get { return txt1.Text; }
set { txt1.Text = value; }
}
如何在我的 ComboBox 下拉菜单中设置所选项目?我尝试了在 TextBoxes 中使用的相同方式,但它不起作用。
//Tried for combobox
public string myCb2
{
get { return cb2.Text; }
set { cb2.SelectedValue = value; }
}
【问题讨论】:
-
你的方法的输出是什么?
-
在我最初的方法中,组合框为空(未选择任何项目)。我使用了 MD.unicorn 的解决方案,现在可以使用了。