c# - How to populate ComboBoxes by lines of a string Array? -
please, wrong here
abc = labguns.text; // multiline label string[] arr = regex.split(abc, "\r\n"); x = 0; foreach (string line in arr) { messagebox.show(line); //works fine - shows each line of label x = x + 1; string abc = "cbguns" + x.tostring(); messagebox.show(abc); //works fine - shows "cbguns1", "cbguns2"... foreach (control c in panprev.controls) { if (c.name == abc) // 5 combos named cbguns1, cbguns2... { c.text = line; //doesn't work. no combo changes text } } } if change last line - c.text = "323" - nothing happened.
so, mistake somewhere near end of code.
this code works (as test):
foreach (control c in panprev.controls) { if (c.name == "cbguns1") { c.text = "323"; } }
if i'm understanding correctly, want add line combobox, not select line in it, correct? in order this, don't set text value of combobox string, need add new comboboxitem combobox, so:
c.items.add(line); instead of
c.text = line; let me know if works!
edit: ok, since you're trying change selected item of combobox, write
c.selecteditem = line;
Comments
Post a Comment