Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is there a fast way to check if there is more than one item with the same key in a ListView ?

 

I'm looking for something faster than having to loop between all items everytime I add a new one.

Now go on, boy, and pay attention. Because if you do, someday, you may achieve something that we Simpsons have dreamed about for generations: You may outsmart someone!

--Homer Simpson

Posted

That's the way ! How stupid can I be sometime... :-(

 

Thanks a lot !

Now go on, boy, and pay attention. Because if you do, someday, you may achieve something that we Simpsons have dreamed about for generations: You may outsmart someone!

--Homer Simpson

Posted

Actually... I tried and it just doesn't work... I also tried the Contains method without anymore success. Here's a piece of code :

 

ListViewItem item1 = new ListViewItem(Serial);
item1.ImageIndex = 0;
item1.SubItems.Add(Serial);
item1.SubItems.Add(GunId);

//Test with IndexOf()
if(lvwBatchItems.Items.IndexOf(item1) > 0)
{
   //Item number already exists
               
}
else
{
   //New item, add it to the list
}


//Test with Contains
if(lvwBatchItems.Items.Contains(item1))
{
   //Item number already exists
               
}
else
{
   //New item, add it to the list
}

 

It's always returning false or -1 depending on the method I use....

Now go on, boy, and pay attention. Because if you do, someday, you may achieve something that we Simpsons have dreamed about for generations: You may outsmart someone!

--Homer Simpson

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...