0
votes

I have two dgvs and two buttons.
dgv1.rows[0].Cells[14].Value is (multiline):
r - red
wh - white
y - yellow
So, divider is not "-" but " - " (space line space)

btn1.Click should split this content so that each line go to separate row (dgv2 is not multiline) and so that left side of dividers go into Columns[0] and right side of dividers go into Columns[1]:
r red
wh white
y yellow
gd gold //user can add this row or delete some another (in dgv2, not in dgv1)

btn2.Click should join this content again and rewrite dgv1 (with the same divider)
Any idea, please?

1

1 Answers

1
votes

Using Linq, you can take each line of multiline textbox and split by space and - then remove empty lines will give you list of items.

var list = textBox1.Lines.Select(s => s.Split(" -".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).ToList();

if you want to join them again you can use string join as

var list2 = list.Select(s => string.Join(" - ", s)).ToList();