【发布时间】:2018-09-14 19:37:06
【问题描述】:
“我知道问题标题可能会重复,但没有找到我正在寻找的解决方案。”
一个组合框,其中包含大约 50 个控件,组合为文本框和组合框。我必须为它们设置值,并且不想写 50 行来为每个控件设置值,所以我想出了下面的代码。但这在组合框的情况下不起作用。或者,如果你们能提出更好的建议,那就太好了。
if(controlsInGroupBox == editStep.Count)
{
int i = 0;
foreach (Control ctr in universalGroupBoxObject.Controls)
{
if (ctr is TextBox)
{
ctr.Text = editStep[i];
}
if (ctr is ComboBox)
{
//ctr.SelectedIndex = cntrlObjListMain.comboBoxLocation.FindStringExact(editStep[i]);
//ctr.SelectedIndex is not working
}
i++;
}
}
【问题讨论】:
-
var combo = (ComboBox)ctr;然后combo.SelectedIndex = ... -
@RezaAghaei 非常感谢它对我有用。