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 = ???
}
2条答案
按热度按时间e0uiprwp1#
您必须将它转换为
ComboBox
,因为Find()
会传回Control
,而Control
不包含SelectedIndex
属性。请尝试以下操作:
jqjz2hbq2#
这种方式看起来更容易https://stackoverflow.com/a/1639106/12537158,你所需要的只是这一行: