Hello all ..

My environment: VS2008/VB using Data Sources (datasets, binding sources, table adapters) to interact with MS Access 2007 database.

My application: A Master form displaying a 4-level hierarchy of data using listboxes instead of grids. Data source for each listbox is a query containing child table data and a stub (foreign key provided by a cross-reference table) to parent record.

Processing: User double clicks Listbox on the Master form to call a popup form bound to child table (to enable data entry). When popup SAVE is clicked, new data is saved to Child table and a new cross-reference record is created to enable future Parent-Child connections. Changes are posted directly to the underlying Access 2007 database.

Problem: On return to Master form, impacted Listbox does not refresh even though I've done another tableadapter.fill on the control. I have been unsuccessful over the last week in finding ANY way to refresh the set of queries that supply data to the Master form or the form itself. When I close/reopen the Master form, Listbox includes the new record.

Need: a way to refresh the Master table without closing/reopening.

Any ideas?

Yes, it's very easy once you know how... you need to raise an event.

First, let's call the event "DataChanged"

Step 1) Open the popup to code view and add the following code under the Class Declaration "PopUp" in this case

Public Class PopUp
Public Event DataChanged()


Step 2) Locate the spot where you actually perform the "Save" to the database... probably under your "Save" button.

After the database save routine executes add the following code;

RaiseEvent DataChanged()

That's all you need to do in the popup form.

Now, let's open the main or calling form (the one with the listboxes)... I'll call that form "MainForm" in this example.

Step 3) Locate the spot where you define form popup.

Private _fPopUp as PopUp

and add the withevents feature.

Private WithEvents _fPopUp as PopUp

Adding 'WithEvents' to the declaration means that "MainForm" will be able to see and respond to events coming from fPopUp.

Step 4) Now you simply need to add a routine to "MainForm" with a handles() declaration pointing to the event.

Private Sub PopUpDataChanged Handles fPopUp.DataChanged
'Refresh all datasets as necessary.
'Fill....
End Sub

Thanks for your suggestions. I look forward to integrating your ideas into my project. Regards.

Thank you very much! This code saved my project!

Maybe you can help me with my next problem:
I'm creating a multi-user application using vb.net and sqlserver. How can I get the dataset to refresh on all instances after an update made by one user?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.