我自动创建控件,我想添加一些特殊控件,这些控件符合另一个控件列表的特定条件。我怎样才能做到这一点?请在伪代码中查看评论。
List<Control> comboBOX;
List<Control> othercomboBOX;
case controls.LIST:
comboBOX.Add(new SpecialComboBox(someparam));
panel.Controls.Add(comboBOX[i])
//Now i have this statement below:
if(somecondition)
{
//Take the newly created combobox which has been added to comboBOX list and add it into another list *othercomboBOX*;
othercomboBOX.Add(the newly created combobox)
}break;
答案 0 :(得分:2)
将new SpecialComboBox
粘贴到变量中并将其添加到两个列表中。
List<Control> comboBOX;
List<Control> otherComboBOX;
case controls.LIST:
ComboBox specialComboBox= new SpecialComboBox(someparam);
comboBOX.Add(specialComboBox);
panel.Controls.add(comboBOX[i]);
//Now i have this statement below:
if(somecondition) {
//Take the newly created combobox which has been added to comboBOX list and add it into another list *othercomboBOX*;
othercomboBOX.Add(specialComboBox);
}break;
答案 1 :(得分:0)
据我理解,您想要拍摄新创建的ComboBox
。所以,只需使用List<Control> comboBOX
使用索引从comboBOX[i]
获取组合框,然后添加到othercomboBox.Add(comboBox[i])
:
case controls.LIST:
comboBOX.Add(new SpecialComboBox(someparam));
panel.Controls.Add(comboBOX[i])
//Now i have this statement below:
if(somecondition)
{
//Take the newly created combobox which has been added to comboBOX list and add it into another list *othercomboBOX*;
othercomboBOX.Add(comboBOX[i])
}break;