我有以下设置:
ComboBox cb1 = new ComboBox();
ComboBox cb2 = new ComboBox();
ComboBox cb3 = new ComboBox();
ComboBox cb4 = new ComboBox();
ComboBox cb5 = new ComboBox();
TableLayoutPanel tlpComboBox = new TableLayoutPanel();
tlpComboBox.ColumnCount = 5;
tlpComboBox.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
tlpComboBox.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
tlpComboBox.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
tlpComboBox.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
tlpComboBox.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
tlpComboBox.Controls.Add(cb1, 4, 0);
tlpComboBox.Controls.Add(cb2, 3, 0);
tlpComboBox.Controls.Add(cb3, 2, 0);
tlpComboBox.Controls.Add(cb4, 1, 0);
tlpComboBox.Controls.Add(cb5, 0, 0);
然后我试图检查 tlpComboBox 中组合框的顺序。要使用文本框执行此操作,我执行了以下操作:
for (i = 0; i < 5; i++)
{
Assert.AreNotEqual(tlpText.Controls[i].Text.ToString(), i.ToString());
}
不幸的是,在 Controls[i] 之后无法访问 SelectedIndex。在使用组合框时,我对为什么有点困惑。
for (i = 0; i < 5; i++)
{
Assert.AreNotEqual(tlpComboBox.Controls[i]. "SelectedIndex isnt accessible", i.ToString());
}
有任何想法吗?
编辑: