c# - How to bind a many to one

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I’m displaying Products & their categories on a form. (1 category can have
many products). I want to bind the controls to the Binding context so that I
can use a currency manager to navigate through the rows. Navigation will be
based on the products, not the categories (I want to show the category of
each product).
I have set up an XML relationship between the Products & Categories.

If I’m setting the currency manager to products, to be able to navigate via
products, how do I bind the categories text box to the categories datasource?

I have tried both programmatically:

this.cboCat.DataBindings.Add("Text",dsMaster,"Products"); (also tried
"Categories")

& I’ve tried setting the control at design time:

DataBindings to dsMaster – Categories.CategoryName
then set the DataSource & DataMember properties of the control.

I can see why this wouldn’t work as it needs to share the same
DataSource/member as the Binding Context, but how do I do this?

Any suggestions would be most appreciated
Ant
 
Just to make sure im right, your core prob. is tat you are having two controls and you wan them to have same binding context.If this is the problem then try this::>>

  • txtname.BindingContext = new BindingContext();
    dgrcon.BindingContext = new BindingContext();
    dgrcon.DataSource = ds;
    dgrcon.DataMember = "t_test";
    dgrcon.BindingContext = txtname.BindingContext;//Making both controls to point to the same bindingcontext
    txtname.DataBindings.Add("Text",ds,"t_test.FirstName");
 
Back
Top