AD.NET 2.0: BindingSource and Parent Child relationship

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,



I have two BindingSource(s) in my form, one for parent and one for child
area.



The unique situation in my form is that the child area chooses its parent by
a ComboBox.



The problem is when I use AndNew method in the child BindingSource, I cannot
choose the parent record through the combobox and parentDataSource.Position.
The parent BindingSource complains about [Not Null] columns and throws
exception.



This doesn't make any sense to me. I shouldn't have to use
DataSet.EnforceConstraints because I do not have any NULL value at that
specific parent record and position!



I am sure that I am missing an important points, what is it?



Any help would be appreciated,

Alan
 
Hi,

A.M said:
Hi,



I have two BindingSource(s) in my form, one for parent and one for child
area.



The unique situation in my form is that the child area chooses its parent
by a ComboBox.



The problem is when I use AndNew method in the child BindingSource, I
cannot choose the parent record through the combobox and
parentDataSource.Position. The parent BindingSource complains about [Not
Null] columns and throws exception.



This doesn't make any sense to me. I shouldn't have to use
DataSet.EnforceConstraints because I do not have any NULL value at that
specific parent record and position!



I am sure that I am missing an important points, what is it?



Any help would be appreciated,

Could you describe the situation a little more. I mean what child and
parent controls are there ? And since you're trying to select a parent when
you add a new child it looks more like a master-lookup scenario which is the
opposite of parent-child binding and is setup differently.

What are you trying to achieve ? To what are the bindingsources bound, to
what and how are the controls bound, what relations are there, what's the
exact error ...


HTH,
Greetings
 
Hi Bart,
Could you describe the situation a little more. I mean what child and
parent controls are there ?

Both parent and child are WinForms textbox controls
And since you're trying to select a parent when you add a new child it
looks more like a master-lookup scenario which is the opposite of
parent-child binding and is setup differently.

That is exactly my situation, Do you know any link to a smple?

What are you trying to achieve ?
master-lookup scenario

To what are the bindingsources bound, to
I have two typed datatable in my typed dataset

what and how are the controls bound,
I have two .NET 2.0 Binding source in my form for parent and child
what relations are there,
The dataset contains a relation between parent and child
exact error ...

The filed in Parent cannot be NULL


Right now, I deleted the relationship and the form works fine. But if you
could send me a sample for master-lookup scenario, it would be a great help


Kind regards,
Alan




Bart Mermuys said:
Hi,

A.M said:
Hi,



I have two BindingSource(s) in my form, one for parent and one for child
area.



The unique situation in my form is that the child area chooses its parent
by a ComboBox.



The problem is when I use AndNew method in the child BindingSource, I
cannot choose the parent record through the combobox and
parentDataSource.Position. The parent BindingSource complains about [Not
Null] columns and throws exception.



This doesn't make any sense to me. I shouldn't have to use
DataSet.EnforceConstraints because I do not have any NULL value at that
specific parent record and position!



I am sure that I am missing an important points, what is it?



Any help would be appreciated,

Could you describe the situation a little more. I mean what child and
parent controls are there ? And since you're trying to select a parent
when you add a new child it looks more like a master-lookup scenario which
is the opposite of parent-child binding and is setup differently.

What are you trying to achieve ? To what are the bindingsources bound, to
what and how are the controls bound, what relations are there, what's the
exact error ...


HTH,
Greetings

 
Hi,

A.M-SG said:
Hi Bart,


Both parent and child are WinForms textbox controls


That is exactly my situation, Do you know any link to a smple?


master-lookup scenario


I have two typed datatable in my typed dataset


I have two .NET 2.0 Binding source in my form for parent and child

The dataset contains a relation between parent and child


The filed in Parent cannot be NULL

Not sure about your error, can't reproduce, but i can show you how a typical
master-lookup binding looks like:

DataSet ds = new DataSet(); // has two tables (with or without relation,
shouldn't matter)
BindingSource productSource = new BindingSource(ds, "Product");
BindingSource categorySource = new BindingSource(ds, "Category");

// bind lookup
ComboBox1.DataSource = categorySource;
ComboBox1.DisplayMember = "CategoryName";
ComboBox1.ValueMember = "CategoryId"; // pk

// bind master fields
ComboBox1.DataBindings.Add("SelectedValue", productSource, "CategoryId");
// fk
TextBox1.DataBindings.Add("Text", productSource, "ProductDesription" );


HTH,
Greetings

Right now, I deleted the relationship and the form works fine. But if you
could send me a sample for master-lookup scenario, it would be a great
help


Kind regards,
Alan




Bart Mermuys said:
Hi,

A.M said:
Hi,



I have two BindingSource(s) in my form, one for parent and one for child
area.



The unique situation in my form is that the child area chooses its
parent by a ComboBox.



The problem is when I use AndNew method in the child BindingSource, I
cannot choose the parent record through the combobox and
parentDataSource.Position. The parent BindingSource complains about [Not
Null] columns and throws exception.



This doesn't make any sense to me. I shouldn't have to use
DataSet.EnforceConstraints because I do not have any NULL value at that
specific parent record and position!



I am sure that I am missing an important points, what is it?



Any help would be appreciated,

Could you describe the situation a little more. I mean what child and
parent controls are there ? And since you're trying to select a parent
when you add a new child it looks more like a master-lookup scenario
which is the opposite of parent-child binding and is setup differently.

What are you trying to achieve ? To what are the bindingsources bound, to
what and how are the controls bound, what relations are there, what's the
exact error ...


HTH,
Greetings

 
Yes, Alan. Could you give us a simple repro step, so that we can deliver
our assistance more quickly?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Kevin,



Thank you for follow up.



Since the code is part of a big/complex component, it would take a while to
write some code to reproduce it.



At this point I removed the relations between data and it works okay without
relationships. I'll work to reproduce the problem with smaller scale code
and then create another post to share it with everybody.



Thanks again,

Alan
 
Thank yoy Bart for sharing the code.

My code does the similar thing, but it also shows the parent data in
separated set of text boxes by changing the popsition of the second binding
source control.

I am going to work on reproducing the problem in smaller scale code and
share it on another post

Kind regards,
Alan




Bart Mermuys said:
Hi,

A.M-SG said:
Hi Bart,


Both parent and child are WinForms textbox controls


That is exactly my situation, Do you know any link to a smple?


master-lookup scenario


I have two typed datatable in my typed dataset


I have two .NET 2.0 Binding source in my form for parent and child

The dataset contains a relation between parent and child


The filed in Parent cannot be NULL

Not sure about your error, can't reproduce, but i can show you how a
typical master-lookup binding looks like:

DataSet ds = new DataSet(); // has two tables (with or without relation,
shouldn't matter)
BindingSource productSource = new BindingSource(ds, "Product");
BindingSource categorySource = new BindingSource(ds, "Category");

// bind lookup
ComboBox1.DataSource = categorySource;
ComboBox1.DisplayMember = "CategoryName";
ComboBox1.ValueMember = "CategoryId"; // pk

// bind master fields
ComboBox1.DataBindings.Add("SelectedValue", productSource, "CategoryId");
// fk
TextBox1.DataBindings.Add("Text", productSource, "ProductDesription" );


HTH,
Greetings

Right now, I deleted the relationship and the form works fine. But if you
could send me a sample for master-lookup scenario, it would be a great
help


Kind regards,
Alan




Bart Mermuys said:
Hi,

Hi,



I have two BindingSource(s) in my form, one for parent and one for
child area.



The unique situation in my form is that the child area chooses its
parent by a ComboBox.



The problem is when I use AndNew method in the child BindingSource, I
cannot choose the parent record through the combobox and
parentDataSource.Position. The parent BindingSource complains about
[Not Null] columns and throws exception.



This doesn't make any sense to me. I shouldn't have to use
DataSet.EnforceConstraints because I do not have any NULL value at that
specific parent record and position!



I am sure that I am missing an important points, what is it?



Any help would be appreciated,

Could you describe the situation a little more. I mean what child and
parent controls are there ? And since you're trying to select a parent
when you add a new child it looks more like a master-lookup scenario
which is the opposite of parent-child binding and is setup differently.

What are you trying to achieve ? To what are the bindingsources bound,
to what and how are the controls bound, what relations are there, what's
the exact error ...


HTH,
Greetings



Alan
 
Thank you Alan.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top