DataBinding Problem with Child tables

  • Thread starter Thread starter Matt Burland
  • Start date Start date
M

Matt Burland

Hi,

I'm having a problem with data binding to a windows form. I have a form that
is bound to a datasource that contains a main table and several subtables
that are related to the main table via a key field. I connect to the
database and read in each table to a dataset using separate OleDbDataAdapter
objects and then I set the relations by adding relations to the dataset's
RelationCollection. So something like this:

Apt1.Fill(myDS.Tables["table1"]);
Apt2.Fill(myDS.Tables["table2"]);

DataRelation myRelation = new
DataRelation("1to2",myDS.Tables["table1"].Columns["Key"],myDS.Tables["table2
"].Columns["Key"]);

Then on my form I bind some of the controls to the main table (after
creating a dataview because I want the thing sorted):

myTextBox.DataBindings.Add(new Binding("Text",myDataView,"Field1"));

And then I bind some other controls to the subtable:

myOtherTextBox.DataBindings.Add(new
Binding("Text",myDataView,"1to2.SubField1"));

Then I set up get a CurrencyManager so that I can move through records on
the main table using buttons on my form to change the Position property:

myCurrencyMan = (CurrencyManager) this.BindingContext[myDataView];

Now the problem is this, when I change text in myTextBox, the underlying
data gets changed and it clear has an original and proposed version
available, but the DataRowState of the row is still "Unchanged". Now if I
move to another record (using the buttons that change the CurrencyManager's
Position), the DataRowState gets updated. Now the real problem is that no
matter what I do, if I change the text in myOtherTextBox (the one bound to
the subtable), although the new value gets to the underlying dataset, the
DataRowState is still "Unchanged" and even moving to another record doesn't
fix it. Because I this I can never update the subtable because Apt2.Update
checks the DataRowState and will ignore those rows that have state
"Unchanged".
Can somebody please tell me what I'm doing wrong? I'm really confused and
frustrated!!

Thanks
 
Matt,

I noticed similar problems with data row states being unchanged until you
moved off them when editing through a grid. However, in VS.net 2003 (.Net
Framework 1.1) this seems to be fixed and you don't need to move off the row
in the grid for Update to work.

Are you running .Net1.1, and can you try it?

Regards,
Neil.
 
I'm using VS2003 Academic edition with .Net Framework 1.1. The only
potentially strange thing I might be doing is that I've wrapped all my
database handling in a class so as to seperate it from the code that handles
the form.


Neil McKechnie said:
Matt,

I noticed similar problems with data row states being unchanged until you
moved off them when editing through a grid. However, in VS.net 2003 (.Net
Framework 1.1) this seems to be fixed and you don't need to move off the row
in the grid for Update to work.

Are you running .Net1.1, and can you try it?

Regards,
Neil.
Matt Burland said:
Hi,

I'm having a problem with data binding to a windows form. I have a form that
is bound to a datasource that contains a main table and several subtables
that are related to the main table via a key field. I connect to the
database and read in each table to a dataset using separate OleDbDataAdapter
objects and then I set the relations by adding relations to the dataset's
RelationCollection. So something like this:

Apt1.Fill(myDS.Tables["table1"]);
Apt2.Fill(myDS.Tables["table2"]);

DataRelation myRelation = new
DataRelation("1to2",myDS.Tables["table1"].Columns["Key"],myDS.Tables["table2
"].Columns["Key"]);

Then on my form I bind some of the controls to the main table (after
creating a dataview because I want the thing sorted):

myTextBox.DataBindings.Add(new Binding("Text",myDataView,"Field1"));

And then I bind some other controls to the subtable:

myOtherTextBox.DataBindings.Add(new
Binding("Text",myDataView,"1to2.SubField1"));

Then I set up get a CurrencyManager so that I can move through records on
the main table using buttons on my form to change the Position property:

myCurrencyMan = (CurrencyManager) this.BindingContext[myDataView];

Now the problem is this, when I change text in myTextBox, the underlying
data gets changed and it clear has an original and proposed version
available, but the DataRowState of the row is still "Unchanged". Now if I
move to another record (using the buttons that change the CurrencyManager's
Position), the DataRowState gets updated. Now the real problem is that no
matter what I do, if I change the text in myOtherTextBox (the one bound to
the subtable), although the new value gets to the underlying dataset, the
DataRowState is still "Unchanged" and even moving to another record doesn't
fix it. Because I this I can never update the subtable because Apt2.Update
checks the DataRowState and will ignore those rows that have state
"Unchanged".
Can somebody please tell me what I'm doing wrong? I'm really confused and
frustrated!!

Thanks
 
Back
Top