|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
About ListView1.Items.ContainsHello,
There is one item(text=123456, no subitem) in ListView1, why the code below return FALSE? MessageBox.Show(ListView1.Items.Contains(New ListViewItem("123456"))) Why? Thank you "yxq" <ga***@163.net> schrieb The Listview does not contain the item because it is a new item that could> Hello, > There is one item(text=123456, no subitem) in ListView1, why the > code below return FALSE? > > MessageBox.Show(ListView1.Items.Contains(New > ListViewItem("123456"))) > > Why? not have been added to the listview before because it's just created before calling Contains. Maybe there's an item with the same text in the listview, but it is not the same object. You have to write a loop to check whether an item is having the same text is already in the listview. Armin Hi,
The ListView.Items.Contains() method takes an (already existing) ListViewItem as argument, and checks for that. In your code, you haven't added the ListViewItem to the ListView at all. The following code will return True : ----------------------------------------------------- Dim lvi as New ListViewItem("123456") ListView1.Items.Add(lvi) MessageBox.Show(ListView1.Items.Contains(lvi)) ----------------------------------------------------- Regards, Cerebrus. Thank you.
Show quoteHide quote "Cerebrus" <zorg***@sify.com> дÈëÏûÏ¢ÐÂÎÅ:1142595114.152665.118***@v46g2000cwv.googlegroups.com... > Hi, > > The ListView.Items.Contains() method takes an (already existing) > ListViewItem as argument, and checks for that. In your code, you > haven't added the ListViewItem to the ListView at all. > > The following code will return True : > ----------------------------------------------------- > Dim lvi as New ListViewItem("123456") > ListView1.Items.Add(lvi) > MessageBox.Show(ListView1.Items.Contains(lvi)) > ----------------------------------------------------- > > Regards, > > Cerebrus. > |
|||||||||||||||||||||||