简体   繁体   English

更新绑定到数据网格的数据

[英]updating a data that is bound to a datagrid

I have a problem that I'm not sure how to go about solving. 我有一个我不确定如何解决的问题。 I have a C# app that receives a list of data items from server and they are bound and displayed in a datagrid. 我有一个C#应用程序,该应用程序从服务器接收数据项列表,并将它们绑定并显示在datagrid中。 The user must then be able to alter them and add or remove items, then commit these changes back to the server. 然后,用户必须能够更改它们并添加或删除项目,然后将这些更改提交回服务器。 the datagrid will basically function as an "edit data" window from pgAdmin 3 or sequel server or whatever, where the user can edit the database table. datagrid基本上将用作pgAdmin 3或续集服务器或其他工具中的“编辑数据”窗口,用户可以在其中编辑数据库表。

I am able to display the items in the datagrid, but not sure how to keep track of all the changes that are made to the list. 我能够在数据网格中显示项目,但不确定如何跟踪对列表所做的所有更改。 When a change is made, the unchanged version of the item must be known as well as the changed version, because the original will need to be deleted and the modified version inserted. 进行更改时,必须知道项目的未更改版本以及更改后的版本,因为将需要删除原始版本并插入修改后的版本。

Does anyone know how to do this? 有谁知道如何做到这一点?

You need to have a view-model which keeps track of the changes. 您需要一个视图模型来跟踪更改。 Basically each item will have a current value, but also the most recent value from the DB. 基本上,每个项目都将具有当前值,但也将具有数据库中的最新值。

public class ViewModel
{
    //collection of subviewmodel to bind to datagrid
}

public class SubViewModel
{
    //Model instance
    //property to expose db value from model instance
    //field to store old db value
}
public class Model
{
    //db value
    //db information
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM