prevent使用C#中的ListView双项? [英] Prevent double entries in ListView using C#?
本文介绍了prevent使用C#中的ListView双项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何可以访问项目添加到的的ListView ?
How can we access the items added to a ListView?
的事情,我要做的是:一个项目添加到列表视图。我要检查,如果该项目添加到列表视图已经是present在ListView。
The thing I have to do is: add an item to the list view. I want to check if the item to add to the listview is already present in the ListView.
我使用C#和Visual Studio 2005。
I'm using C# and Visual Studio 2005.
推荐答案
的的 的ListView
类提供了一些不同的方法来确定一个项目是否存在:
The ListView
class provides a few different methods to determine if an item exists:
- 使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.contains.aspx"相对=nofollow>
包含
上的产品
收集 - 使用
FindItemWithText
方法
它们可以以下列方式使用:
They can be used in the following manner:
// assuming you had a pre-existing item
ListViewItem item = ListView1.FindItemWithText("test");
if (!ListView1.Items.Contains(item))
{
// doesn't exist, add it
}
// or you could find it by the item's text value
ListViewItem item = ListView1.FindItemWithText("test");
if (item != null)
{
// it exists
}
else
{
// doesn't exist
}
// you can also use the overloaded method to match sub items
ListViewItem item = ListView1.FindItemWithText("world", true, 0);
这篇关于prevent使用C#中的ListView双项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文