Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I dont think I saw something like this, i searched through net but all i could find is using foreach loop.

here I have the Listviews

What I wanted to do was If listview1 dont have any items named "Joshua", it will change listview2's "Joshua" from "Incomplete" to "Complete".

listview1 can have 2 or more "Joshua", so until all the "Joshua" are gone the listview2 must stay "Incomplete". when all the "Joshua" are gone in Listview1, thats when listview2's "joshua" be "Complete".

this must be the output.

I had put this in the timer1_tick since listview1 Items can be removed when time expires.(working and doing its job removing listview items that expires)

What I have tried:

I used for loop, but it doesnt change incomplete to complete. i think i might be wrong at the looping itself.

this is my code
C#
for (int lst = 0; lst < listView2.Items.Count; lst++)
{
    for (int dgv = 0; dgv < dataGridView1.Rows.Count; dgv++)
    {
        if (listView2.Items[lst].SubItems[0].Text == listView1.Items[dgv].SubItems[0].Text )
        {
            continue;
        }
        else if (listView2.Items[lst].SubItems[0].Text != listView1.Items[dgv].SubItems[0].Text ) 
        {
            listView2.Items[lst].SubItems[1].Text = "Complete";
        }
    }
}
Posted
Updated 14-Sep-17 6:27am
v2
Comments
Maciej Los 12-Sep-17 15:12pm    
Share your code...
Richard MacCutchan 12-Sep-17 15:27pm    
Just count all the "Joshua" entries in Listview1.
Member 10406401 14-Sep-17 2:52am    
Is it a Winform or WPF

1 solution

for (int secondLst = 0; secondLst < listView2.Items.Count; secondLst ++)
{//iterate through each item in the 2nd list view
for(int firstList = 0; firstList < listView1.Items.Count; firstList ++) //compare the item from the 2nd list view to each item in the first listview
{
if (secondLst == firstList)
{
//found a match so do something.
//you can keep searching for other matches or
break; //if your done searching
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900