ListViewItems / ContainsKey Question  
Author Message
Corey Furman





PostPosted: Visual Basic General, ListViewItems / ContainsKey Question Top

I have been looping thru my listviewitems to see if a particular one already exists. I guess it works well, but I'm concerned what it will be like when I have many items

I stumbled onto the ContainsKey method of the items, but I don't seem to be able to get it to do anything useful. If I create a new project and drop a listview and a button on the form, I put this code in:


Visual Basic12  

 
 
smallstonefan





PostPosted: Visual Basic General, ListViewItems / ContainsKey Question Top

Hi there,

You're 90% there! You need to use an overloaded method of Items.Add() and specify a key. Right now, you're specifying the display text but no key. Change your statement like this and your code will work:

Dim item As ListViewItem = ListView1.Items.Add(ItemName, ItemName, 6)

 

James

www.jamesfoxall.com

 


 
 
Corey Furman





PostPosted: Visual Basic General, ListViewItems / ContainsKey Question Top

Bam. That was it. Thanks!

 
 
smallstonefan





PostPosted: Visual Basic General, ListViewItems / ContainsKey Question Top

You bet! :)

James

www.jamesfoxall.com