DataTable.NewRow() clears previous row?! BUG?

  • Thread starter Thread starter Tomas R
  • Start date Start date
T

Tomas R

I have a datagrid with a dataview(created from a DataTable) bind to it. It displayes coordinates and I have a toolbarbutton that will create a set of new coordinates just like the existing ones, accept that the x-values is mirrored. It's also possible to remove these coordinates, by a method that removes any row with negative x-values. This usually works fine a few times, mirroring and then removing. But then suddenly the NewRow statement returns the same object as the last one in my DataRowCollection!?! I've put traces just before and after the NewRow statement, and the last DataRow in the DataTables DataRowCollection is cleared and sat the the same object as the onw returned from newRow!?! THAT my friends seem to me like a BUG!
I've also put traces to see what the DataView(comming from the datagrid) contains, and just after the NewRow statement the last DataRowView becomes DETACHED!?!

int start = noOfCoordinates - 1;
DataRow newRow;
for( int i = start; i >= 0; i-- )
{
newRow = myDataTable.NewRow();
newRow.ItemArray = new object[] {
Guid.NewGuid(),
NextSequenseNumber(),
++noOfCoordinates,
-1 * coords[0],
coords[1] };
myDataTable.Rows.Add( newRow );
myDataTable.AcceptChanges();
}

Any ideas folks? Cause I'm really frustrated know... :-P

Kind regards/
Tomas R
 
Here's some trace output before NewRow:
*___
Unchanged, False; 1, 500, 4600
Unchanged, False; 2, 500, 5000
Unchanged, False; 3, 500, 4600
Unchanged, False; 4, -500, 4600
Unchanged, False; 5, -500, 5000
*___

Current, Unchanged, False; IsEdit
Current, Unchanged, False; 2, 500, 5000
Current, Unchanged, False; 3, 500, 4600
Current, Unchanged, False; 4, -500, 4600
Current, Unchanged, False; 5, -500, 5000

And here's some trace output just after NewRow

___*
Unchanged, False; 1, 500, 4600
Unchanged, False; 2, 500, 5000
Unchanged, False; 3, 500, 4600
Unchanged, False; , , <--------The values have dissappered?!
Unchanged, False; 5, -500, 5000
___*

Current, Unchanged, False; IsEdit
Current, Unchanged, False; 2, 500, 5000
Current, Unchanged, False; 3, 500, 4600
Current, Detached, False; IsEdit <-------The DataRowView hase become Detached?!
Current, Unchanged, False; 5, -500, 5000

An unhandled exception of type 'System.Data.ConstraintException' occurred in system.data.dll
Additional information: Column 'figurid, figursekvensnr, sekvensnr' is constrained to be unique. Value 'de41ab35-63be-489d-be9d-f9a48c8e4b6c, 2, 6' is already present.

Well, why not even include some of the trace code. I'll do anything to get some help on this issue:

if( dgKoordinater.DataSource is DataView )
{
DataView dv = (DataView) dgKoordinater.DataSource;
DataTable tab = dv.Table;
if( tab.Rows.Count > 0 )
{
System.Diagnostics.Debug.WriteLine( gagga );
foreach( DataRow row in tab.Rows )
{
System.Diagnostics.Debug.Write( row.RowState.ToString() + ", " + row.HasErrors );
try{
System.Diagnostics.Debug.WriteLine("; " + row[2].ToString() + ", " + row[3].ToString() + ", " + row[4].ToString() );
} catch { System.Diagnostics.Debug.WriteLine("; *");
}
}
}
if( dv.Count > 0 )
{
System.Diagnostics.Debug.WriteLine( gagga );
foreach( DataRowView row in dv )
{
System.Diagnostics.Debug.Write( row.RowVersion.ToString() + ", " + row.Row.RowState.ToString() + ", " + row.Row.HasErrors );
if( row.IsNew )
System.Diagnostics.Debug.WriteLine("; IsNew");
else if( row.IsEdit )
System.Diagnostics.Debug.WriteLine("; IsEdit");
else
System.Diagnostics.Debug.WriteLine("; " + row[2].ToString() + ", " + row[3].ToString() + ", " + row[4].ToString() )
}
}



"Tomas R" <[email protected]> skrev i meddelandet I have a datagrid with a dataview(created from a DataTable) bind to it. It displayes coordinates and I have a toolbarbutton that will create a set of new coordinates just like the existing ones, accept that the x-values is mirrored. It's also possible to remove these coordinates, by a method that removes any row with negative x-values. This usually works fine a few times, mirroring and then removing. But then suddenly the NewRow statement returns the same object as the last one in my DataRowCollection!?! I've put traces just before and after the NewRow statement, and the last DataRow in the DataTables DataRowCollection is cleared and sat the the same object as the onw returned from newRow!?! THAT my friends seem to me like a BUG!
I've also put traces to see what the DataView(comming from the datagrid) contains, and just after the NewRow statement the last DataRowView becomes DETACHED!?!

int start = noOfCoordinates - 1;
DataRow newRow;
for( int i = start; i >= 0; i-- )
{
newRow = myDataTable.NewRow();
newRow.ItemArray = new object[] {
Guid.NewGuid(),
NextSequenseNumber(),
++noOfCoordinates,
-1 * coords[0],
coords[1] };
myDataTable.Rows.Add( newRow );
myDataTable.AcceptChanges();
}

Any ideas folks? Cause I'm really frustrated know... :-P

Kind regards/
Tomas R
 
Back
Top