我必须按名称处理一些控件
this.Controls.Find(String.Format("lbl{0}", index),
true)[0].Text = data[i].ToString();
但是当我尝试按名称获取Combobox时,它无法显示SelectedIndex属性
this.Controls.Find(String.Format("cmbDat{0}", index), true)[0].
我可以做什么?
答案 0 :(得分:1)
您需要将其投放到ComboBox
,因为Find()
会返回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 = ???
}