Databound listbox not updating

I have a list box bound to a Name property in a custom class. How do I make it show changed data  I have a NameChanged event and when I trap that in the form and show the listbox.text value in the debug window it is different to what is seen in the list. How do I refresh it

Answer this question

Databound listbox not updating

  • JohnCNTS

    The ListBox will only update itself if the list it's bound to is an IBindingList.  This class has change notification, so it lets the ListBox know that something has changed.  If you want to refresh it yourself, you can tell it to SuspendBinding, set your property, then resume binding


       BindingContext[myobjs].SuspendBinding(); //My ListBox's DataSource is myobjs
       myobjs[1].foo = 5; //Set the property you're interested in
       BindingContext[myobjs].ResumeBinding();

  • ianic

    The class does implement IBindingList and it is receiving the change notification. As I said if I trap the change and write the value of the listbox text property to the immediate window I see the new value but the list still shows the old one. The control is just not refreshing.
  • Chear

    not exactly efficient, but won't it work if you just set the DataSource Property again to your custom class or whatever you set it to the first time around
  • Databound listbox not updating