Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to Share Bound Data Across Forms?

$
0
0

I'm looking for ideas on how to implement this functionality.

The information system we use at work, apparently developed in .NET, has the following feature. Suppose you have a window with a grid of invoices and a VCR-style navigator bar. You can double click on a row to open an invoice in full view. This new window, showing a single invoice, has its own VCR-style navigator bar, which you can use to move to a different invoice. Here's the thing -- the list of invoices shown in the grid and the list of invoices shown single-view isthe same list of invoices.

It's not just the same invoices. The record selectors in both windows are synchronized. If you navigate to a different invoice in the single-view window, the selector in the grid of invoices in theother window changes too. As well, if you close the first window, the one with the grid of invoices, that invalidates the list the single-view window was using. The VCR-style navigator becomes disabled, except for the Save button, which still worksfor that record.

I would like to replicate that behavior. I found the article How to: Share Bound Data Across Forms Using the BindingSource Component. The main idea is to pass the BindingSource from the first to the second window. However, that works only if you don't wish to update the underlying date while in the second window. BindingSource can update the in-memory DataSet, but (unless I'm wrong), to update the database itself, you need access to the TableAdapterManager or TableAdapter. And you need to reference the DataSet when using the TableAdapterMangerthis.tableAdapterManager.UpdateAll(this.MyDataSet); so just passing the BindingSource to the second form doesn't work.

It seems that all the data components need to be shared between the two forms (DataSet, TableAdapter, TableAdapterManager, and BindingSource). But how to do that?

It somehow seems poor practice to pass that much data in the constructor. Put them in a separate class and use them in common between the two forms?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>