The trick is to bind the child element to the relation.  E.g.

// Bind the Master
masterGrid.SetDataBinding(customerTable, "");

// Bind the Detail
detailGrid.SetDataBinding(customerTable, "Customers_Invoices");

Thanks,

Shawn Wildermuth
[EMAIL PROTECTED]

> -----Original Message-----
> From: The DOTNET list will be retired 7/1/02
> [mailto:[EMAIL PROTECTED]] On Behalf Of Michel Broggi
> Sent: Monday, June 03, 2002 5:40 AM
> To: [EMAIL PROTECTED]
> Subject: [DOTNET] Databinding related tables
>
>
> Hi,
>
> I'm trying to find out what the correct way is to bind two
> related tables to winform textboxes. The scenario is the following:
>
> I have a form showing customer information as well as 1-n
> adresses. The customer information comes from one table, the
> adresses from another. In the form, the user sees the
> selected customers information and the default mailing
> address. He can choose to view another adress by selecting
> the relevant entry in a combobox.
>
> I retrieved the data as follows:
>
>  (...code abbreviated)
>
>  _daKunden.Fill(_dsKunden,"Kunden");
>  _daAdressen.Fill(_dsKunden, "Adressen");
>
>  _dsKunden.Relations.Add("KundenAdressen",_dsKunden.Tables
> ["Kunden"].Columns["IDKunde_PK"], _dsKunden.Tables["Adressen"].Columns
> ["IDKunde_FK"]);
>
>
> In the form I bind the main customer data to the controls as follows:
>
>  DataViewManager dvm = new DataViewManager(_dsKunden);
>
>  cboKunden.DataSource =  dvm;
>  cboKunden.DisplayMember = "Kunden.FullName";
> cboKunden.ValueMember = "Kunden.IDKunde_PK";
>
>  txtName.DataBindings.Add("Text",dvm, "Kunden.Name");
> txtBemerkungen.DataBindings.Add("Text",dvm, "Kunden.Bemerkungen");
>
>  (...code abbreviated)
>
> This works. When I select a different customer in the
> combobox (cboKunden) all textboxes show the new information.
> Also can I pass any updates through the dataadapter's update
> method to the db.
>
> What's not working is the display of the related adresses.
> Here is what I've tried:
>
>  dvm.DataViewSettings["Adressen"].RowFilter="IDKunde_FK = " +
> cboKunden.SelectedValue.ToString();
>  cboAdresse.DataSource =  dvm;
>  cboAdresse.DisplayMember = "Adressen.Typ";
>
>  txtStrasse.DataBindings.Add("Text",dvm, "Adressen.Adresse");
>
> On the first customer shown in the form, this works fine and
> I can select a different adress through the adress combobox
> (cboAdresse) to show the information. When I move to a
> different customer the information does not get updated.
>
> So I've added the following to the SelectedIndexChanged of
> the customer
> combobox:
>
>  DataViewManager dvm = new DataViewManager(_dsKunden);
> dvm.DataViewSettings["Adressen"].RowFilter="IDKunde_FK = " +
> cboKunden.SelectedValue.ToString();
>  cboAdresse.DataSource =  dvm;
>  cboAdresse.DisplayMember = "Adressen.Typ";
>
> As expected, this updates the combobox but not any of the
> related textboxes. Do I have to redefine the binding on all
> the textboxes after every change of the customer? I don't
> think this is the most efficient way of doing it, but I'm
> kind of stuck.
>
> Does anyone have a suggestion on how to keep the two tables
> in sync, and leaving the possibility open of updating either
> table through the dataadapter?
>
> Michel
>
> You can read messages from the DOTNET archive, unsubscribe
> from DOTNET, or subscribe to other DevelopMentor lists at
> http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to