I’m making a combobox “readonly” in this way:
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
// for this to work, set the comboboxes' Tag to its SelectedIndex after setting that
ComboBox cb = sender as ComboBox;
int validSelection = Convert.ToInt32(cb.Tag);
if (cb.SelectedIndex != validSelection )
{
cb.SelectedIndex = validSelection;
}
}
…and then trying to set all of the comboboxes on the form to that handler like this:
foreach (Control c in this.Controls)
{
if (c is ComboBox)
{
(c as ComboBox).SelectedValueChanged += comboBox1_SelectedValueChanged;
}
}
…but the if condition is never equating to true; there are several ComboBoxes on the form…???
The ComboBoxes are most likely inside other panels.
Try going through them recursively: