2

I have a combobox that is populated by a database table I have. In my Load event for my form I have it populated by...

Me.BusinessTableAdapter.Fill(Me.BillingdbDataSet.Business)

My problem is whenever I "add", "edit", or "delete" a business I have stored I can't find a way to update the combobox I have. Whenever I exit and reopen my program and I can see the changes but was hoping someone could inform me on how to have it updated after a change has happened.

kapa
  • 77,694
  • 21
  • 158
  • 175
daveomcd
  • 6,367
  • 14
  • 83
  • 137
  • Could you not put the Adapter.Fill code into a function and recall that whenever to want a refresh. – Ash Burlaczenko Nov 20 '10 at 20:58
  • I forgot to mention that when I do "Add" and "Edit" these launch an additional form and then after that it goes back to my combobox form. I tried your suggestion also on my "Delete" button since it stays on the same form and it did not work. – daveomcd Nov 20 '10 at 21:05

2 Answers2

2

The problem is you need something that implements INotifyCollectionChanged.

MSDN

You can enumerate over any collection that implements the IEnumerable interface. However, to set up dynamic bindings so that insertions or deletions in the collection update the UI automatically, the collection must implement the INotifyCollectionChanged interface. This interface exposes the CollectionChanged event, an event that should be raised whenever the underlying collection changes.

You can refresh it manually, but the ideal situation is the bind to an observable collection class - http://msdn.microsoft.com/en-us/library/ms668604.aspx HTH

Wade

Wade73
  • 4,359
  • 3
  • 30
  • 46
  • I've been looking it over, but I guess since I'm still fairly new to vb I haven't been able to get it to work. Might anyone have some example/pseudo code? Thanks! – daveomcd Nov 23 '10 at 17:01
  • http://stackoverflow.com/questions/253843/simple-datagridview-refresh-questionThis looks like they're doing what I'm wanting, but to a datagridview instead of a combobox. I don't actually create a List like they have there however. My combobox is populated by my BindingSource. Does the bindingsource provide a list i can access? – daveomcd Nov 24 '10 at 15:02
1

If you're using datasets you can use the dataview class which raises events when the underlying dataset is changed. Then you could either look into data binding them to the combo-box or write your own update code and put that in an event handler for the event raised when the list changes.

Moonshield
  • 925
  • 9
  • 16