J
Jerry
I'm having a BindingContext problem. I have a Windows Form with several
controls on it that are intended to display data from different tables in a
DataSet. There are ChildRelations defined for the DataSet so that all of the
display data relates back to an active entry. When the DataSet is filled and
I set the BindingContext position for the Form all of the data is display
correctly. The problem I'm having is when I create a new blank enty. During
the loading of the Form I create new rows in the DataSet and set the key
values to establish the parent child relationships for the new rows. The
ContextBinding position is set to this new active entry. As I then edit the
display values all seems to be fine. I can inspect the DataSet and see the
changes being recorded. Then I apply the changes (updating the data source
with specific rows of data related to the active enty, not the entire
DataSet). I can inspect the DataSet at this point and all looks good.
However as control is returned back to the Window Form all of the control
seem to disconnect from the DataSet and their displays are blank. Do I need
to adjust the BindingContext in some way after the update. The row positions
haven't change so the BindingContext position should be ok. I don't have
this problem when I modify data that preexisted in the DataSet, it is only
when I add the rows for the new entry.
Below is the code that creates the BindingContext and binds the data to some
of the controls. Am I missing something?
//Identify DataRow of interest
DataRowCollection drcEntry = EntryDataSet.Tables["entries"].Rows;
for( intEntryRow = 0; intEntryRow < drcEntry.Count; intEntryRow++ )
if( (int)drcEntry[intEntryRow]["entry_id"] == EntryId )
{
//Create and initialize BindingContext
this.BindingContext = new BindingContext();
this.BindingContext[EntryDataSet, "entries"].Position = intEntryRow;
break;
}
//Bind controls to DataSet
txtID.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToDescriptors.identifier"));
txtDescription.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToDescriptors.description"));
cboConfig.DataSource = ViewConfig;
cboConfig.DisplayMember = "description";
cboConfig.ValueMember = "ce_id";
cboConfig.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToConfigs.description"));
controls on it that are intended to display data from different tables in a
DataSet. There are ChildRelations defined for the DataSet so that all of the
display data relates back to an active entry. When the DataSet is filled and
I set the BindingContext position for the Form all of the data is display
correctly. The problem I'm having is when I create a new blank enty. During
the loading of the Form I create new rows in the DataSet and set the key
values to establish the parent child relationships for the new rows. The
ContextBinding position is set to this new active entry. As I then edit the
display values all seems to be fine. I can inspect the DataSet and see the
changes being recorded. Then I apply the changes (updating the data source
with specific rows of data related to the active enty, not the entire
DataSet). I can inspect the DataSet at this point and all looks good.
However as control is returned back to the Window Form all of the control
seem to disconnect from the DataSet and their displays are blank. Do I need
to adjust the BindingContext in some way after the update. The row positions
haven't change so the BindingContext position should be ok. I don't have
this problem when I modify data that preexisted in the DataSet, it is only
when I add the rows for the new entry.
Below is the code that creates the BindingContext and binds the data to some
of the controls. Am I missing something?
//Identify DataRow of interest
DataRowCollection drcEntry = EntryDataSet.Tables["entries"].Rows;
for( intEntryRow = 0; intEntryRow < drcEntry.Count; intEntryRow++ )
if( (int)drcEntry[intEntryRow]["entry_id"] == EntryId )
{
//Create and initialize BindingContext
this.BindingContext = new BindingContext();
this.BindingContext[EntryDataSet, "entries"].Position = intEntryRow;
break;
}
//Bind controls to DataSet
txtID.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToDescriptors.identifier"));
txtDescription.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToDescriptors.description"));
cboConfig.DataSource = ViewConfig;
cboConfig.DisplayMember = "description";
cboConfig.ValueMember = "ce_id";
cboConfig.DataBindings.Add(new Binding("Text", EntryDataSet,
"entries.EntriesToConfigs.description"));