You will get an error when executing the comboBox3_SelectedIndexChanged method on a line
Int32.TryParse(comboBox3.SelectedValue.ToString(), out val);
Since comboBox3.SelectedValue is null if no element was selected in the ComboBox element, I did not see in your code that you selected some elements before calling comboBox3_SelectedIndexChanged for the first time.
Because the comboBox3_SelectedIndexChanged method executed inside Form.Load , an event handler exception was not shown. Check this out: fooobar.com/questions/392916 / ....
That's why you didn’t get any errors
You need to check SelectedValue for null before using it
If(this.comboBox3.SelectedValue is null) { this.comboBox4.DataSource = null; //Remove all items if nothing selected } else { Int32 val= (Int32)this.ComboBox3.SelectedValue; string query = "SELECT id, name FROM data_symptom WHERE organ_system_id = " + val; fillCombo(this.comboBox4, query, "name", "id"); }
Since you use a DataBinding when populating a ComboBox elements, it is logical to use the SelectedValueChanged event handler
private void comboBox3_SelectedValueChanged(object sender, EventsArgs e) {
source share