Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BindingContext Position
Message
De
04/12/2003 21:17:07
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
BindingContext Position
Divers
Thread ID:
00856135
Message ID:
00856135
Vues:
65
Here's an interesting one folks ... and, FWIW, I think it may be a bug.

When deleting a row from a DataTable, the BindingContext's .Position automatically gets decremented.
// BindingContext[MyTable].Position is initially 5
MyTable.DefaultView[5].Row.Delete();
// BindingContext[MyTable].Position will now be equal to 4
This is fine, and I certainly don't have a problem with this behavior. However ... if my BindingContext[MyTable].Position is 0 and I delete that zero-th row from MyTable, the .Position automatically gets decremented to -1. Again, that is not a problem in itself ... but it seems that once the BindingContext .Postion gets down to -1, nothing on earth can reset it to anything else. I've tried and failed. It's like .NET is assuming that once that happens, you have no more rows in the table, even though you do.

My workaround is this:
if (i == 0 && MyTable.DefaultView.Count > 1)
    this.BindingContext[MyTable].Position = 1;
// Now I can safely delete
MyTable.DefaultView[i].Row.Delete();
// And my Position drops down to 0
Anyone know of a way around this, other than the workaround I've discovered? Is this a bug or what? I'd appreciate a reasonable explanation as to this behavior. Just seems wrong to me ...

TIA,
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform