Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
[no name] 23-Nov-12 11:02am    
Try to check each items of ListBox1 with each items of ListBox2..
Member 8197122 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 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: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 23-Nov-12 14:28pm    
the code which you have given is showing error. Please give me the correct one

1 solution

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.
 
Share this answer
 

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

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900