Как скомбинировать listbox
Есть:
listbox1, в нём: 123, abc
listbox2 в нём: 987, zxc
Нужно в listbox3 скомбинировать: 123987, 123zxc, abc987, abczxc.
Есть код, но он подряд в listbox комбинирует, а нужно построчно
string result = "";
for (int i = 0; i < listBox1.Items.Count; i++)
for (int j = 0; j < listBox2.Items.Count; j++)
result += $"{listBox1.Items[i]}{listBox2.Items[j]}";
result = result.TrimEnd(new char[] { ',', ' ' });
listBox3.Items.Add(result);
Ответы (1 шт):
Автор решения: Yotic
→ Ссылка
//listBox1.Items = 123, abc
//listBox2.Items = 987, zxc
//listBox3.Items = 1[0]2[0], 1[0]2[1], 1[1]2[0], 1[1]2[1]
for (int i = 0; i < listBox1.Items.Count; i++)
for (int j = 0; j < listBox2.Items.Count; j++)
listBox3.Items.Add(listBox1[i] + listBox12[j]);