changing datasource

Posted on 2006-03-29
Medium Priority
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

Accepted Solution

e1v earned 1000 total points
ID: 16327017
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

579 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