Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Have been trying to find a bit of code that will update a listbox in a windows form application with no luck.

When form loads this code populates the list, which works just fine:
private void Form1_Load(object sender, EventArgs e)
      {
          lbItemsList.DataSource = shoppingBasket.OrderItems;
      }


The listbox "lbItemsList" is binded to a class list called "shoppingBasket". When I add new items to the list then try to run the same line again, nothing happens. How can I update the listbox?

I've already tried the .Refresh() and .Update() methods and none of them work.
Posted
Updated 28-Oct-12 9:48am
v4

1 solution

try this code
C#
lbItemsList.BeginUpdate();
lbItemsList.DataSource = null;
lbItemsList.DataSource = shoppingBasket.OrderItems;
lbItemsList.EndUpdate();
 
Share this answer
 
Comments
FourCrate 28-Oct-12 17:55pm    
Thanks Cagri, it worked.

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



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