如何在listview2中检查listview1项目是否不再存在并触发事件? [英] How can I check if listview1 item in not present anymore in listview2 and fire an event?

查看:92
本文介绍了如何在listview2中检查listview1项目是否不再存在并触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不认为我看到过这样的东西,我通过网搜索但是我能找到的只是使用foreach循环。



我有Listviews



我想做的是如果listview1没有任何名为的项目Joshua,它会将listview2的Joshua从Incomplete改为Complete。



listview1可以有2个或更多Joshua,所以在所有Joshua消失之前,listview2必须保持不完整。当所有Joshua在Listview1中消失时,那就是当listview2的joshua为Complete时。



这必须是输出。



我把它放在timer1_tick中,因为listview1项目可以在时间到期时删除。(工作和完成工作,删除过期的listview项目)



我尝试过:



我用于循环,但它没有完全改变不完整。我想我可能在循环中错了。



这是我的代码

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

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";
        }
    }
}

推荐答案

for(int secondLst = 0; secondLst< listView2 .Items.Count; secondLst ++)

{//遍历第二个列表视图中的每个项目

for(int firstList = 0; firstList< listView1.Items .Count; firstList ++)//将第二个列表视图中的项目与第一个列表视图中的每个项目进行比较

{

if(secondLst == firstList)

{

//找到匹配所以做点什么。

//你可以继续搜索其他比赛或

打破; //如果你完成了搜索

}

}

}
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
}
}
}


这篇关于如何在listview2中检查listview1项目是否不再存在并触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆