// in the constructor
ListView lv = new ListView();
lv.Items.Add("Apple");
lv.Items.Add("Banana");
lv.Items.Add("Cherry");
// in a button
if(lv.Items.Contain(new ListViewItem("Apple")))
MessageBox.Show("Found");
else
MessageBox.Show("Didn't found");
If condition fails all the time. Any idea?
Thanks,
-CL
> if(lv.Items.Contain(new ListViewItem("Apple")))
> MessageBox.Show("Found");
> else
> MessageBox.Show("Didn't found");
>
> If condition fails all the time. Any idea?
You are testing two different ListViewItems, which
just happen to have the same text. You can either
keep the reference to the original item, or iterate
through all items in the Items collection and check
the Text property for each.
bool FindInCollection(ListViewItemCollection collection,string text)
{
foreach(ListViewItem item in collection)
if (item.Equals(text))
return true;
return false;
}
If you have any further questions, be free to let me know, thanks!
Kind regards,
Ying-Shen Yu [MS]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| From: =?ISO-8859-1?Q?Christian_Fr=F6schlin?= <froes...@mvtec.com>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Subject: Re: search item in listview
| Date: Tue, 26 Aug 2003 18:52:45 +0200
| Organization: (posted via) Mnet Telekommunikations GmbH
| Lines: 15
| Message-ID: <3F4B905...@mvtec.com>
| References: <07fa01c36bea$14c88230$a001...@phx.gbl>
| NNTP-Posting-Host: host-62-245-183-130.customer.m-online.net
| Mime-Version: 1.0
| Content-Type: text/plain; charset=us-ascii; format=flowed
| Content-Transfer-Encoding: 7bit
| X-Trace: svr8.m-online.net 1061916768 3030 62.245.183.130 (26 Aug 2003
16:52:48 GMT)
| X-Complaints-To: ab...@m-online.net
| NNTP-Posting-Date: Tue, 26 Aug 2003 16:52:48 +0000 (UTC)
| User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1)
Gecko/20020823 Netscape/7.0
| X-Accept-Language: en-us, en, ja
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!newsfeed.freenet.de!news.space.net!news.m-online.net!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:50943
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
Kind regards,
Ying-Shen Yu [MS]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| X-Tomcat-ID: 37540730
| References: <07fa01c36bea$14c88230$a001...@phx.gbl>
<3F4B905...@mvtec.com>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: v-...@online.microsoft.com (Ying-Shen Yu[MSFT])
| Organization: Microsoft
| Date: Wed, 27 Aug 2003 01:32:37 GMT
| Subject: Re: search item in listview
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| Message-ID: <0eOlasDb...@cpmsftngxa06.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Lines: 63
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:50972
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122