I have a ListView with 2 columns. For example's sake, we'll say it looks like this:
ColA | ColB
-----------------
001 |
002 |
003 |
004 |
005 |
I have a text file that contains the following lines:
001
002
004
005
008
I'm trying to read through the file line by line, and if the number matches a number in ColumnA, I want to add it to ColumnB. That works fine (see my example below). However, I'd also like to add any non-matches as a new ListViewItem. I can't figure that part out. Here's what I have so far:
foreach (string textfileitem in TheTextFile)
{
foreach (ListViewItem item in ListView1.Items)
{
var existingitem = item.SubItems[0];
if (existingitem.Text == textfileitem)
{
item.SubItems[1].Text = textfileitem;
}
}
}
I'm not sure how to handle any non-matches and add them to the ListView. the end result would look like this:
ColumnA | ColumnB
-----------------
001 | 001
002 | 002
003 |
004 | 004
005 | 005
- | 008
As always, your help is appreciated!