ListViewItems / ContainsKey Question

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:


Answer this question

ListViewItems / ContainsKey Question

  • SPWilkinson

    Bam. That was it. Thanks!

  • Ori'

    You bet! :)

    James

    www.jamesfoxall.com


  • mattdawg

    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

     


  • ListViewItems / ContainsKey Question