views:

295

answers:

1

Hey All,

I've got a strongly typed dset, w/two datatables: Parent and Child, w/a relation linking them in the way you'd expect (e.g. parent-has-many-children).

On my Child Detail form, I show lots of info on the current child, w/binding calls like so:

me.txtBirthDate.DataBindings.add(New Windows.Forms.Binding("Text", MyDataset, "Child.Birthdate"))

But I would also like to show some info on the child's parent--say, the parent's name. I have tried:

me.txtParentName.DataBindings.add(New Windows.Forms.Binding("Text", MyDataset, "Child.Parent.Name"))

and

me.txtParentName.DataBindings.add(New Windows.Forms.Binding("Text", MyDataset, "Parent.Name"))

But these both result in a blank text box.

I can of course put the parent properties directly on the Child DataTable & fill them w/the results of a join between the underlying db tables, but I'd like to avoid that if it's possible (my real app involves just a few Parents each w/many many Children & I'd like not to be moving so much unnecessary data).

Is that possible?

Many thanks!

-Roy

A: 

I usually use a BindingSource between the DataSet and the controls. When using this approach, if I have controls that I want to bind to a related row from a different table, I create a new BindingSource, which points at the related row (his DataSource property is the original BindingSource, his DataMember is the parent table), and then bind the other controls to the 2nd BindingSource.

I usually do it all in the designer view, which just creates those BindingSource objects as I go along.

Hope that helps.

Noam Gal
Thanks much--I tried the BindingSource, but it wasn't obvious how I could use it to get at the parent.I wound up just handling the child's CurrencyManager.CurrentChanged event, and calling .GetParentRows there. IOW, I'm not using binding for those fields.Thanks for taking the time!
Roy Pardee