Moving a row between 2 datasets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

C#

I have a screen with 2 datagrids on it. The screen is designed for
allocating records from one datagrid to the other. Once a record has moved
from one to the other, i refresh them both to show the change. To do the
refresh though, currently I am sending a request back to the DB to refetch
the records, which can obviously have performance hits.

I have been able to refresh the datagrid which is losing the record, by
creating a new dataset, merging the old data into it, and then removing the
relevant row from this dataset before rebinding the grid to it:

dsData topGridDS = new dsData();

topGridDS.Merge(initialTopDS.Job);

topGridDS.Job.Rows.Remove(topGridDS.Job.FindByJobID(....))

datagrid1.datasource = topGridDS...
....
...

so this refreshes the datagrid that is losing a row, without going back to
the DB to refresh. But how do I do the reverse process, of adding the moved
row into a new dataset? If I use the AddRow method it complains that the row
already belongs to a dataset. I thought maybe I could use the CopyTo method
but I cant work out how to use that either.

Thanks

Steve
 
Use the ItemArray of the original DataRow to get the data in it, and then
use the same ItemArray to fill a new row in the receiving table.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Back
Top