one listbox controls population of another listbox

Posted on 2006-03-28
Last Modified: 2010-04-16
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?
Question by:rmmarsh
    LVL 6

    Accepted Solution

    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);

    Author Comment

    Thank you, that did it...

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Add row in datatable 18 43
    How to check if an MS Word is closed in C# 21 56
    prevent lose focus 6 50
    import issue in bit values 3 37
    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now