c# - How to set same button events for ListBox (value) index or treeview nodes? -
i have c# win-form shown below. have few array menu list-box.
public string[] arraymain = {"1.water","2.air","3.soil","4.fire"}; public string[] arraywater = {"1.salty","2.fresh", "3.contaminated"}; public string[] arraysalty = {"1.aa", "2.bb", "3.cc"}; public string[] arrayfresh = {"1.dd", "2.ee", "3.ff"}; public string[] arraycontaminated = {"1.xx", "2.yy", "3.zz"} ; public string[] arrayair = {"1.fresh", "2.contaminated"}; public string[] arraysoil = {"1.normal", "2.contaminated"}; public string[] arrayfire = {"1.low","2.mid","3.high"};
when application start in main list-box loaded first array values.
public form1() { initializecomponent(); listboxmain.items.addrange(arraymain); listview1.items.add(arraymain[0]) // user choose: 1.water }
if user press button 1 application clears main list-box , loads selection. time list-box loaded with;
listboxmain.items.addrange(arraywater); listview1.items.add(arraymain[0]) // user choose: 1.salty
now if user press button 2 application clears main list-box , selected menus list-box have values like;
1.water 1.salty 2.bb
then application first letter (number) fixed format like;
112
and send wfc service. wfc services know "112". major problem have set button list-box index (or combo-box say). example if user press button 1 first time user have select menus array list-box. , again if user press button 1 button 1 have connected list-box index (new values).
in previous question interesting problem user @eugene suggested me can turn logic tree-view. , stated as;
where nodes contain items combo-box (key-string show, value - value use later). when push buttons add respective node item queue , load new items. in leaf nodes contain action> call respective service method (for many options can same action)
i try apply many logic , spend 10 days make simulator works expected, failed. realy have information can set button 1 events listbox (index) or treview (nodes). if point me, how set button 1 events stated above rest easy me.
kind regards,
first time app start:
after user press buttons:
thank @eugene. made it. here is.
for main;
public form1() { initializecomponent(); treenode tnode; //main node 1 tnode = treeview1.nodes.add("1.water"); tnode = treeview1.nodes.add("2.air"); tnode = treeview1.nodes.add("3.soil"); tnode = treeview1.nodes.add("4.fire"); // water node treeview1.nodes[0].nodes.add("1.salty"); treeview1.nodes[0].nodes.add("2.fresh"); treeview1.nodes[0].nodes.add("3.contaminated"); // air node treeview1.nodes[1].nodes.add("1.fresh"); treeview1.nodes[1].nodes.add("2.contaminated"); // soil node treeview1.nodes[2].nodes.add("1.normal"); treeview1.nodes[2].nodes.add("2.contaminated"); // fire node treeview1.nodes[3].nodes.add("1.low"); treeview1.nodes[3].nodes.add("2.mid"); treeview1.nodes[3].nodes.add("3.high"); // salty node treeview1.nodes[0].nodes[0].nodes.add("1.aa"); treeview1.nodes[0].nodes[0].nodes.add("2.bb"); treeview1.nodes[0].nodes[0].nodes.add("3.cc"); // fresh node treeview1.nodes[0].nodes[1].nodes.add("1.dd"); treeview1.nodes[0].nodes[1].nodes.add("2.ee"); treeview1.nodes[0].nodes[1].nodes.add("3.ff"); // contaminated node treeview1.nodes[0].nodes[2].nodes.add("1.xx"); treeview1.nodes[0].nodes[2].nodes.add("2.yy"); treeview1.nodes[0].nodes[2].nodes.add("3.zz"); //clear listbox items listboxmain.items.clear(); //load listbox first time foreach (treenode n in treeview1.nodes) { listboxmain.items.add(n.text); } }
for buttons:
// btn 1 private void btn_1_click(object sender, eventargs e) { int value = 1 - 1; int icount = listboxmain.items.count; if (icount > value) { string item = listboxmain.items[value].tostring(); treviewnodesselection(item, value); } } // btn 2 private void btn_2_click(object sender, eventargs e) { int value = 2 - 1; int icount = listboxmain.items.count; if (icount > value) { string item = listboxmain.items[value].tostring(); treviewnodesselection(item, value); } }
then created treviewnodesselection:
//treviewnodesselection private void treviewnodesselection(string item, int value) { textbox1.text = item; listboxmenu.items.add(item); //find nodes first traverse(treeview1.nodes, item); //clear listbox items listboxmain.items.clear(); //get first childnode via parenet name if (treeview1.selectednode.nodes.count != 0) { foreach (treenode v in treeview1.selectednode.nodes) { listboxmain.items.add(v.text); } } else { messagebox.show("now can start calculation..."); } }
and treeview node selection
private void traverse(treenodecollection nodes, string findtext) { foreach (treenode node in nodes) { if (node.text.tostring().trim() == findtext) { node.treeview.selectednode = node.nextnode; treeview1.selectednode = node; node.treeview.focus(); //messagebox.show(node.text + " selected..."); } traverse(node.nodes, findtext); } }
i learn lot http://stackoverflow.com few cent contribution.
kind regards
Comments
Post a Comment