forms - c# how can i get my listbox item and add it quickly when i pressed checklistboxes -
hello still confuse how can listbox items , when click every checklistboxes , want add numbers , display in textbox. example check checklistbox index 1 contains 300 display in textbox. check index 2 of checkboxlist contains 100 display 400. if check index 3 of checkboxlist contains 200 display 600 in checkbox.
my code:
namespace ggg { public partial class form1 : form { public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { } private void checkedlistbox1_selectedindexchanged(object sender, eventargs e) { listbox1.items.clear(); listbox2.items.clear(); textbox1.clear(); foreach (string s in checkedlistbox1.checkeditems) listbox1.items.add(s); foreach (int in checkedlistbox1.checkedindices) { if (i == 0) { listbox2.items.add(300); decimal total = 300; textbox1.text += total; } if (i == 1) { listbox2.items.add(100); decimal total = 100; textbox1.text += total; } if (i == 2) { listbox2.items.add(200); decimal total = 200; textbox1.text += total; } } } } }
you can sum listbox items . after , can set total textbox
int total = 0; (int = 0; < listbox2.items.count; i++) { total = total+ int.parse(listbox2.items[i].tostring()); } textbox1.text = total.tostring(); 
Comments
Post a Comment