Hi @Michael Bahr , Welcome to Microsoft Q&A,
You treat the ComboBox
control as a more general Control
class, which does not have an Items
property. This results in compiler error CS1061.
In order to correctly add items to a ComboBox
, you need to explicitly cast the Control
type to the ComboBox
type before you can access its Items
property.
for (int r = 0; r < tblRinks.Controls.Count; r++)
{
Control control = tblRinks.Controls[r];
if (control is ComboBox comboBox && comboBox.Name == "cboRink2B")
{
foreach (string team in Globals.rList)
{
string tname = team;
if (tname != ((Control)sender).Text && tname != cboRink1A.Text)
{
comboBox.Items.Add(tname);
}
}
comboBox.BackColor = Color.LightGoldenrodYellow;
((Control)sender).BackColor = Color.White;
return;
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.