Click here to Skip to main content
12,750,191 members (34,698 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
How we can remove the listbox items which are not exists in another listbos?

I have given an example here....

ListBox1 items are....


ListBox2 items are....


Please note that, items "Five" and "Six" in ListBox2 are not exists in ListBox1. So, these two should be deleted.

So, please guide me in this regard.
Posted 23-Nov-12 5:57am
Krunal R 23-Nov-12 11:02am
Try to check each items of ListBox1 with each items of ListBox2..
Richard MacCutchan 23-Nov-12 11:47am
This is a simple piece of homework that you should be able to do yourself. Figure out how you would do it with two lists written on pieces of paper and then convert that into the relevant code.
Member 8197122 23-Nov-12 12:41pm

Thanks for your early reply. As you said I tried to do. But not able to do. And got an idea about the removing the items which are matching. But not able to figure it out to remove which are not matching. If you could send me the example code I will ge obliged to you. Thanks in advance
Member 8197122 23-Nov-12 12:44pm

Can you reply with some example code. Since its getting very difficulty for me to figure it out. If you could it will help me lot.
Member 8197122 23-Nov-12 14:28pm
the code which you have given is showing error. Please give me the correct one
Member 8197122 26-Nov-12 0:48am
Sir..the code which have suggested me is not working . so, will it be possible to suggest me in detail.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

for each item in ListBox2
  if not item exists in ListBox1
    delete item

The ListBox documentation[^] will help you figure out the rest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170215.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100