one listbox controls population of another listbox

I apologize in advance if this has already been asked, but I couldn't find a solution.

I have two listboxes.  When I click on listbox1, it controls what is placed in listbox2.  I then want to select something from listbox2 and put both selections in two textboxes.

My problem is when I select from listbox1, it populates listbox2 and then listbox2, thinking it's index has been changed (it has, just not manually) populates the two textboxes. The index on listbox2 is set to 0, but that is a valid selection.

How can I tell if the listbox2 item has been manually selected or is just being populated?
rmmarshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

e1vCommented:
You could remove the eventhandler for listbox2.SelectedIndexChanged in the code for populating listbox2 and re-add it when you're done.

Like this:

listBox2.SelectedIndexChanged -= listBox2_SelectedIndexChanged;
//populate listbox2 and selectindex=0
listBox2.SelectedIndexChanged += new System.EventHandler(listBox2_SelectedIndexChanged);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmmarshAuthor Commented:
Thank you, that did it...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.