What you are currently doing, is checking if a full line is equal to one single comma (
richtextstring == ","
) or
\r\n
which won't help if you want to retrieve comma-separated items. Also, a line of
.Lines
will never be equal to
"\r\n"
because that is treated as line separator (so not as a part of the line itself) so
.Lines
will exclude it.
You appear to be interested in two things: the lines of the RichTextBox and the comma-separated items. For the former, you can use
.Lines
(as you did), and for the latter, you can use
.Split(',')
.
It's not entirely clear when you want to create a new item in the ListView, but if I understand it correctly, you want to create a new item for every comma-separated item and repeat that for each line. You can do that like this:
if (richTextBox2.Lines.Length == 0)
{
MessageBox.Show("Load some data first");
return;
}
foreach (string line in richTextBox2.Lines)
{
string[] commaSeparatedItems = line.Split(',');
foreach (string item in commaSeparatedItems)
{
listView1.Items.Add(item);
}
}
If the above is not what you intended, then you can probably transform it into what you actually want to do.