简体   繁体   English

XtraGrid已被修改

[英]XtraGrid has been modified

I need to know if an XtraGrid has been modified (value changed or rows added). 我需要知道XtraGrid是否已修改(值更改或添加行)。

I can make a boolean var and change it on GridView_CellValueChanged : 我可以创建一个boolean var ,并在GridView_CellValueChanged上进行更改:

void suppGridView_CellValueChanged(object sender, CellValueChangedEventArgs e) {
    isModified = true;
}

or 要么
I can read all DataSource and check the DataRow.RowState property value ( Modified or Added ): 我可以读取所有DataSource并检查DataRow.RowState属性值( ModifiedAdded ):

foreach (DataRow row in dataSource.Rows) {
    if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added) 
        return true;
}

Do you know a simpler method? 您知道更简单的方法吗?

You can know whether the data table changed in the following way: 您可以了解数据表是否以以下方式更改:

DataTable changes = table.GetChanges(DataRowState.Added | DataRowState.Modified);
bool isModified = (changes != null);

here table is a DataTable. 这里的table是一个数据table
From msdn : 来自msdn

DataTable.GetChanges Method: DataTable.GetChanges方法:
Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState. 获取DataTable的副本,该副本包含自上次加载以来或自调用AcceptChanges以来对其所做的所有更改,并由DataRowState过滤。

Remark: If no rows of the desired DataRowState are found, the method returns null . 备注:如果找不到所需DataRowState的行,则该方法返回null

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

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