Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

How do I refresh a databinded array to update a listbox?

How do I refresh a databinded array to update a listbox?
I have an array of objects bounded to a listbox.  If I add a new object to the array then how do I get it displayed in the listbox?  All of the objects that were members of the array before the databinding calls show up fine in the listbox, but what about removing and adding objects to the array?
0
alexmac05
Asked:
alexmac05
  • 2
  • 2
1 Solution
 
surajgupthaCommented:
If you add new objects to the array you have to rebind the array to the list or refresh it.
0
 
alexmac05Author Commented:
How do I rebind the array to the list?  How do I refresh it?

listBoxOfProductForAlerts.DataSource = arrayOfProducts;
listBoxOfProductForAlerts.DisplayMember = "getProduct";

These calls, bind it.  What rebinds it?  what refreshes it?

Thanks,
alex
0
 
alexmac05Author Commented:
I just did this and it worked.  Would you recommend doing this as a solution?

listBoxOfProductForAlerts.DataSource = null;
listBoxOfProductForAlerts.DisplayMember = null;

Then rebinding it again with:
listBoxOfProductForAlerts.DataSource = arrayOfProducts;
listBoxOfProductForAlerts.DisplayMember = "getProduct";
           
0
 
surajgupthaCommented:
yeah that should do just fine. there is no need to set the datasource back to null. You can just use

listBoxOfProductForAlerts.DisplayMember = "getProduct";
listBoxOfProductForAlerts.DataSource = arrayOfProducts;

You can leave out the null assignment statements
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now