Can't use typed list row after removing it

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 31-Mar-2005 22:03:26   

Is it possible to remove a row from a typed list and then use the row that was just removed? I have the following code where I am pulling an instance of a row out of the typed list collection then I remove the row from the list, but want to continue to use the row on its own. I am passing the fork typed list row into the BuildForkTable method, but an error is thrown saying "This row has been removed from a table and does not have any data". I know that I can do this using an entity collection, but can it be done with a typed list?


// Get current fork from collection.
ForksRow fork = (ForksRow)this.forks[rowIndex];
// Remove fork from collection after its been found.
this.forks.Rows.Remove(fork);
// Build selected fork table
this.BuildForkTable(rowIndex, fork);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Apr-2005 12:18:12   

No, you can't do that, a datarow needs a datatable to live. That's the reason I wrote my own entity classes instead of using a datarow class as base class, because it doesn't have an own constructor, it needs a datatable.

The only thing you could do is adding it to another instance of the typed list (but with no data). The other instance will give you the column definitions, so the row should be addable. (you have to use datatable.ImportRow)

Frans Bouma | Lead developer LLBLGen Pro