Here is some code that works, although it is not an ideal implementation. But it does at least show how the
SelectedIndexChanged
event should be handled.
ComboBox[] combo_for_constraint;
void SetupCombos()
{
int count = 3;
combo_for_constraint = new ComboBox[count];
int combo_for_constraint_x = 250, combo_for_constraint_y = 50;
for (int i = 1; i < count; i++)
{
combo_for_constraint[i] = new ComboBox();
combo_for_constraint[i].Location = new System.Drawing.Point(combo_for_constraint_x,
combo_for_constraint_y + (i * 10));
combo_for_constraint[i].Size = new Size(100, 50);
combo_for_constraint[i].Name = "combo_for_constraintbx" + i.ToString();
combo_for_constraint[i].DropDownStyle = ComboBoxStyle.DropDownList;
this.Controls.Add(combo_for_constraint[i]);
this.ResumeLayout(false);
combo_for_constraint_y += 40;
this.Refresh();
combo_for_constraint[i].Items.Add("UNIQUE");
combo_for_constraint[i].Items.Add("PRIMARY KEY");
combo_for_constraint[i].Items.Add("FOREIGN KEY");
combo_for_constraint[i].SelectedIndex = 0;
}
combo_for_constraint[1].SelectedIndexChanged += new System.EventHandler(Combo1_SelectedIndexChanged);
}
void Combo1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;
if (comboBox == combo_for_constraint[1] && combo_for_constraint[1].Text == "PRIMARY KEY")
{
combo_for_constraint[2].Items.RemoveAt(1);
combo_for_constraint[2].DroppedDown = true;
}
}