The relationship between tableadapters and bindingsource

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Here is a simple scenario

There is a form with a the following objects on it:

a dataset called MyDataSet
a tableadapter called CustomersTableAdapter
CustomersTableAdapter has two methods, .Fill which returns all customers in the Customers table and .FillActive which returns all customers with open orders only.
a bindingsource called bsCustomers
a 2 page tabpage control on it.
tabpage 1 has a combobox bound to bsCustomers with displaymember being CustomerName

Now this is where I get confused?

The setup above works and I see all customers in the combobox.

Now when I change to tabpage 2 I want the combobox on this tabpage to list the data returned by the CustomersTableAdapter.FillActive method.

But does this mean that the table Customers in the dataset MyDataSet will now only show active customers? When I go back to tabpage 1 will that combobox now be showing the wrong data?

The more I try to get my head around this the more I get confused.

I dont know if I should have multiple bindingsources/tableadapters or create new datasets or what and if so how to link them all together:confused:
 
First, have a read of this forum's sticky "dataset or reader?"

This will explain the roles of the various components you find on your form


The setup above works and I see all customers in the combobox
Because of the call to .Fill(theDataSet.Customers) in Form_Load

Now when I change to tabpage 2 I want the combobox on this tabpage to list the data returned by the CustomersTableAdapter.FillActive method.
So, make a call to .FillActive(theDataSet.Customers) in the relevant event for changing tab controls. Note, of course that this requires a database operation; it may lag the user interface.

But does this mean that the table Customers in the dataset MyDataSet will now only show active customers?
I think you mean to say "contain active customers"
Yes, that is what it means. The tableadapter clears the table, then refills it with only active customers. both combo boxes show only active customers

When I go back to tabpage 1 will that combobox now be showing the wrong data?
If you assert "wrong" in this context to mean "not (all customers)" then yes, it will show the wrong data

I dont know if I should have multiple bindingsources/tableadapters or create new datasets
It really depends on why you have two tab pages at all. The simplest solution is to set the .Filter of the bindingsource that both combos bind through, to "[Active] = Yes" or Nothing respectively. Note the colours are deliberate!

There wont be a significant performance hit in this, because youre using comboboxes, which means (being a good HCI observer) you wont ever be loading more than ~20 customers into the datatable and hence either combo at any one time will be showing no more than 20 records, right?
 
It really depends on why you have two tab pages at all. The simplest solution is to set the .Filter of the bindingsource that both combos bind through, to "[Active] = Yes" or Nothing respectively. Note the colours are deliberate!

There wont be a significant performance hit in this, because youre using comboboxes, which means (being a good HCI observer) you wont ever be loading more than ~20 customers into the datatable and hence either combo at any one time will be showing no more than 20 records, right?

LOL :)

Well I have two tabpages as, well that is part of the design. In fact I have 8 in all each of which allows interaction with different sections of the app.

I actually stumbled across the .Filter method by chance searching this forum and gave it a go and it works a treat. I'm glad my end solution matches your suggestion ;)
 
Back
Top