Please, what is 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) // five combos named cbGuns1, cbGuns2...
{
c.Text = line; //doesn't work. No combo changes its text
}
}
}
If I change last line to – c.Text = "323" – also nothing happened.
So, mistake is obviously somewhere near the end of code.
This code also works (as test):
foreach (Control c in panPrev.Controls)
{
if (c.Name == "cbGuns1")
{
c.Text = "323";
}
}
If I’m understanding you correctly, you want to add a line to a Combobox, not select a line currently in it, correct? In order to do this, you don’t set the Text value of the Combobox to a string, you need to add a new ComboboxItem to the Combobox, like so:
instead of
Let me know if this works!
EDIT:
Ok, since you’re trying to change the selected item of the Combobox, I would just write