M
Mark Olbert
There appears to be a very serious bug in the BindingContext's position handling code. When a
BindingContext object is based on a DataView, and a new record is added to the DataView, the
BindingContext object will not "allow" you to position onto the new record.
The following code adds a new record to a DataTable that is the basis for a DataView object called
formView.
The last line is the one that fails.
// DataView formView = new DataView(dataTableBehindView); // (occurs earlier in life cycle of form)
this.BindingContext[formView].EndCurrentEdit(); // so new record doesn't trample pending edits
DataRow newRow = OnNewRecord(); // creates the new record; works fine
dataTableBehindView.Rows.Add(newRow);
formView.Sort = "displayfield"; // without this line, DataView doesn't "recognize" the new DataRow
// this next line correctly finds the new row in the DataView (e.g., row #2)
int rowNum = formView.Find(newRow["value of display field in new row"]);
// this line FAILS; Position has the same value before and after the assignment,
// and no exceptions are thrown, even though Position != rowNum (!!!)
this.BindingContext[formView].Position = rowNum;
Any workarounds for this problem would be most appreciated!
I'd also like to know how in the world an assignment statement can fail without any exceptions being
thrown. That's just downright goofy.
- Mark
BindingContext object is based on a DataView, and a new record is added to the DataView, the
BindingContext object will not "allow" you to position onto the new record.
The following code adds a new record to a DataTable that is the basis for a DataView object called
formView.
The last line is the one that fails.
// DataView formView = new DataView(dataTableBehindView); // (occurs earlier in life cycle of form)
this.BindingContext[formView].EndCurrentEdit(); // so new record doesn't trample pending edits
DataRow newRow = OnNewRecord(); // creates the new record; works fine
dataTableBehindView.Rows.Add(newRow);
formView.Sort = "displayfield"; // without this line, DataView doesn't "recognize" the new DataRow
// this next line correctly finds the new row in the DataView (e.g., row #2)
int rowNum = formView.Find(newRow["value of display field in new row"]);
// this line FAILS; Position has the same value before and after the assignment,
// and no exceptions are thrown, even though Position != rowNum (!!!)
this.BindingContext[formView].Position = rowNum;
Any workarounds for this problem would be most appreciated!
I'd also like to know how in the world an assignment statement can fail without any exceptions being
thrown. That's just downright goofy.
- Mark