-1

我必须按他们的名字处理一些控件

this.Controls.Find(String.Format("lbl{0}", index),
            true)[0].Text = data[i].ToString();

但是当我尝试按名称获取组合框时,它无法显示 SelectedIndex 属性

this.Controls.Find(String.Format("cmbDat{0}", index), true)[0].

我能为谁做?

4

1 回答 1

3

您需要将其转换为 a ComboBox,因为Find()返回 a Control,其中不包含该SelectedIndex属性。

试试这个:

ComboBox theComboBox = this.Controls.Find(String.Format("cmbDat{0}", index), true) as ComboBox;

// Verify the combo box was found before trying to use it
if(theComboBox != null)
{
    // Do whatever you want with the combo box here
    theComboBox.SelectedIndex = ???
    theComboBox.Text = ???
}
于 2013-10-31T17:50:23.570 回答