ultraman Posted July 28, 2004 Posted July 28, 2004 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. Quote 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
Administrators PlausiblyDamp Posted July 28, 2004 Administrators Posted July 28, 2004 Could you now use it's .Items.IndexOf to see if it finds an existing match? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ultraman Posted July 28, 2004 Author Posted July 28, 2004 That's the way ! How stupid can I be sometime... :-( Thanks a lot ! Quote 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
ultraman Posted July 29, 2004 Author Posted July 29, 2004 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.... Quote 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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.