Complicated Data Binding Question

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

I've included a picture below to show what I am trying to accomplish.
It is best to copy/paste into notepad to get the spacing correct.

I have a dataset that contains 3 tables. Two of the tables contain
data and the third links them together. The dataset has a constraint
setup as well.

The first listbox and the first and last name text box are bound to
the Person DataTable. As you select a name in the listbox, the
textbox will be updated with the appropriate name. You can make
modifications to the name and have them updated in the listbox.

This works just fine. Now for the problem.

I need to have the second listbox populated with entries that are
specific to the person that is selected in the first listbox. This
restriction prevents me from directly binding to the Address
DataTable. Once I have the filtered data , I will then need to have
the same editing capabilities as listed above.

Ideally, I would like to do databinding as I will be writing the
values back into the database. I'm just not sure how to filter and
bind at the same time.

If you have a code example somewhere or just a basic "here's what you
need to do" list or any thoughts on how to accomplish this, I would
love to hear about it.

Thanks,
Dave


+--------------+ +--------------+ +--------------+
| Person | | Person2Addr | | Address |
+--+-----------+ +--+-----------+ +--+-----------+
|PK| ID |>---|PK| PersonID |---<|PK| ID |
| | LastName | |PK| AddressID | | | City |
| | FirstName | +--+-----------+ | | State |
+--+-----------+ +--+-----------+



+-----------------------------------------------------------+
| +------------+ +------------+------------------------+ |
| | Listbox | | First Name:| Jane | |
| +------------+ +------------+------------------------+ |
| | Smith,Jane | | Last Name: | Smith | |
| | Smith,John | +------------+------------------------+ |
| +------------+ |
| |
| +--------------+ +--------+----------------------------+ |
| | Listbox | | City: | St. Louis | |
| +--------------+ +--------+----------------------------+ |
| | St.Louis, MO | | State: | MO | |
| | Raleigh, NC | +--------+----------------------------+ |
| +--------------+ |
+-----------------------------------------------------------+
 
The Binding class along with the DataBindings property of Windows Forms was
designed for situations like this. Basically you bind specific values to the
various controls using the same Binding. The underlying currency manager
ensures that all the controls stay in sync. If you change the position of
the binding within one control the other controls sharing the same binding
automatically change position as well. Refer to the Binding class and
CurrencyManager for links to samples on how to get this stuff working.

Michael Taylor - 7/3/05
 
Yes, I realize that. I stated that I had binding already working.

What I want to know is...
Given an item selected in listbox1 how to lookup all the AddressIDs in
Person2Addr and bind only those records from Address to ListBox2.

Cheers,
Dave
 
You could use DataBinding. I am assuming that either you are using Typed
DataSet or atleast know how to create Relationships.
Create the following Relationships:
PersonToPerson2Addr (Link the Person Table to Person2Addr Table)
Person2AddrToAddress (Link the Person2Addr Table to Address Table)
Try this.

DataGrid1.SetDataBinding(dsDataSet.tbl_Person, "");
DataGrid2.SetDataBinding(dsDataSet.tbl_Person,
"PersonToPerson2Addr.Person2AddrToAddress");

The code above will make sure that when you change a selection in DataGrid1,
only the related information will be shown in DataGrid2. Also this is not
just limited to DataGrids (Check the spellings, I might be a little of, do
not have the IDE to make sure).

--rythm


Person | | Person2Addr | | Address
 
Back
Top