changing datasource

Posted on 2006-03-29
Last Modified: 2012-05-05
I have a listbox which has a datasource set to a List collection.

I'm trying to remove an item from the List, and then reload the listbox - expecting to see the removed item no longer present in the listbox.  Here is the code to do that:

            listBox1.DataSource = source;
            listBox1.DisplayMember = "str";

For some reason the listbox remains the same after I execute this code.  I know the code is getting reached since if I execute it enough times, an exception is raised, since there are no more items left to remove from the List.  Thannks!
Question by:ARACK04
    1 Comment
    LVL 6

    Accepted Solution

    List<> does not support automatic notification of changes to bound controls. To do that you have to use a BindingList<>
    When you set DataSource after the RemoveAt, nothing will change since it's the same daataSource.
    This should work:

    listBox1.DataSource = null;
    listBox1.DataSource = list;

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 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

    21 Experts available now in Live!

    Get 1:1 Help Now