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
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