I'm using a RadGridView to display items. On a doubleclick the user comes to a detail view where he can edit the contents and then comes back (both usercontrols are displayed as tabs on screen and are thus existing simultaneously).
I'm using a working method to update the edited list in the grid view without reloading the whole gridview:
dataRow = (GridViewRowInfo)element.Data;
Worker displayedWorker = (Worker)edataRow.DataBoundItem;
Worker changedWorkerFromDataBase = GetWorkerFromDataBase(displayedWorker.WorkerNumber).FirstOrDefault();
List<Worker> tableDataSource = (List<Worker>)MyGridView.DataSource;
int indexInTableDataSource = tableDataSource.IndexOf(tableDataSource.Where(e => e.WorkerNumber == displayedWorker.WorkerNumber).First());
tableDataSource[indexInTableDataSource] = changedWorkerFromDataBase;
dataRow.InvalidateRow();
Like mentioned this code works, but when I change the IndexOf method to:
int indexInTableDataSource = tableDataSource.IndexOf(displayedWorker);
it doesn't work any longer as expected. The above code works once and only once after a second save the objects stored inside the MyGridView.DataSource and the one stored inside the dataRow.DataBoundItem are seen as being different resulting in the indexOf returning -1.
This behaviour surprised me quite a lot especially as the first method works without problems and I had thought that the dataBound item of the row is just a pointer towards the items inside the GridView datasource.
Thus my question here is: Can (after the update is done) I tell the row to update/refresh its databound item so that it is equal again to the one from the gridview (aka seen as the same object) ?
Aucun commentaire:
Enregistrer un commentaire