Grupy dyskusyjne Google nie obsługują już nowych postów ani subskrypcji z Usenetu. Treści historyczne nadal będą dostępne.

search item in listview

1 wyświetlenie
Przejdź do pierwszej nieodczytanej wiadomości

Ching-Lung

nieprzeczytany,
26 sie 2003, 11:52:4126.08.2003
do
How do I search for an item in a list view?

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

Christian Fröschlin

nieprzeczytany,
26 sie 2003, 12:52:4526.08.2003
do
Ching-Lung wrote:

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

Ying-Shen Yu[MSFT]

nieprzeczytany,
26 sie 2003, 21:32:3726.08.2003
do
Hi Ching-Lung,
I agree with froeschlin, and I'd like to provide more information. the
Contains method would return if an reference of item is stored in this
collection. To do a search based on content, you should iterate the
Collection just like:

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

Ying-Shen Yu[MS]

nieprzeczytany,
28 sie 2003, 22:58:4628.08.2003
do
Hi Ching-Lung,
Contains method do comparation by the Equal method, However the
ListViewItem as well as ListviewSubItem didn't override the Equal method,
so they are using the default implementation in Object, which only compares
their reference.
To find an Item by value, I think do an iteration is a much simpler and
direct, although you may create your own class by deriving the ListViewItem
and ListViewSubItem, 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.
--------------------

| 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

Nowe wiadomości: 0