Click here to Skip to main content
11,416,572 members (59,547 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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....

One
Two
Three
Four

ListBox2 items are....

One
Two
Three
Four
Five
Six

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.
Ashu
Posted 23-Nov-12 5:57am
Comments
Krunal R at 23-Nov-12 11:02am
   
Try to check each items of ListBox1 with each items of ListBox2..
Member 8197122 at 23-Nov-12 12:41pm
   
Mr.Krunal,

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
Richard MacCutchan at 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 at 23-Nov-12 12:44pm
   
Mr.Richard,

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 at 23-Nov-12 14:28pm
   
the code which you have given is showing error. Please give me the correct one
Member 8197122 at 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
good
Please Sign up or sign in to vote.

Solution 1

for each item in ListBox2
  if not item exists in ListBox1
  then
    delete item
  endif
endfor
The ListBox documentation[^] will help you figure out the rest.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,295
1 OriginalGriff 7,592
2 Maciej Los 3,718
3 Abhinav S 3,456
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web04 | 2.8.150427.4 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2015
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