c# - ComboBox selection returning IndexOutofBounds Error -
i setting such choice of first combobox(name = combo3) determines second combobox(name = combo4) show. works fine.
now trying make second combobox determine third combobox show. doesn't work. moment make selection on second combox, jams , returns error. if hard code value of 2nd combobox, works.
i getting indexoutofbounds exception. problem seems method private void combobox_selectionchanged2(). please advice wrong. thanks.
mainwindow
string[] tablearray = { "agent_name", "agent_age", "agent_gender", "agent_alias", "security_clearance", "dept_id", "job_id", "mission_id" }; string[] attributearray = { "mission_name", "mission_description", "mission_country", "mission_city" }; private void combobox_selectionchanged1(object sender, selectionchangedeventargs e) { if (((comboboxitem)combo3.selecteditem).content.tostring() == "agents") { combo4.items.clear(); foreach (string x in tablearray) { combo4.items.add(x); } } else { combo4.items.clear(); foreach (string x in attributearray) { combo4.items.add(x); } } } private void combobox_selectionchanged2(object sender, selectionchangedeventargs e) { combo5.items.clear(); messagebox.show(combo4.text); //debugging line returns empty shouldn't case. chose mission_name should show mission_name. //fillcombo("select * " + combo3.text + ";", "mission_name", combo5); //works fillcombo("select * " + combo3.text + ";", combo4.text, combo5); // not working } private void fillcombo(string query, string name, combobox c) { mysqlcommand cmdreader = new mysqlcommand(query, conn); mysqldatareader myreader; myreader = cmdreader.executereader(); while (myreader.read()) { string temp = myreader.getstring(name); c.items.add(temp); } myreader.close(); }
xaml:
<combobox x:name="combo3" width="120" selectionchanged="combobox_selectionchanged1"> <comboboxitem x:name="box3" content="agents"/> <comboboxitem x:name="box4" content="missions"/> </combobox> <combobox x:name="combo4" width="120" selectionchanged="combobox_selectionchanged2"> </combobox> <combobox x:name="combo5" width="120" canvas.left="818" canvas.top="588"/>
error message:
an unhandled exception of type 'system.indexoutofrangeexception' occurred in mysql.data.dll
additional information: not find specified column in results:
how combo boxes looks.
replace this
messagebox.show(combo4.text);
with this:
messagebox.show(combo4.selectedtext);
or this:
messagebox.show(combo4.selecteditem.tostring());
replace everywhere use combo4.text as-well combo1 2 3 , on
Comments
Post a Comment