本文整理汇总了C#中System.Data.DataViewRowState枚举的典型用法代码示例。如果您正苦于以下问题:C# DataViewRowState枚举的具体用法?C# DataViewRowState怎么用?C# DataViewRowState使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了DataViewRowState枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DemonstrateRowState
static private void DemonstrateRowState()
{
// Create a DataTable with one column.
DataTable dataTable = new DataTable("dataTable");
DataColumn dataColumn = new DataColumn("dataColumn");
dataTable.Columns.Add(dataColumn);
// Add ten rows.
DataRow dataRow;
for (int i = 0; i < 10; i++)
{
dataRow = dataTable.NewRow();
dataRow["dataColumn"] = "item " + i;
dataTable.Rows.Add(dataRow);
}
dataTable.AcceptChanges();
// Create a DataView with the table.
DataView dataView = new DataView(dataTable);
// Change one row's value:
dataTable.Rows[1]["dataColumn"] = "Hello";
// Add one row:
dataRow = dataTable.NewRow();
dataRow["dataColumn"] = "World";
dataTable.Rows.Add(dataRow);
// Set the RowStateFilter to display only added and modified rows.
dataView.RowStateFilter = DataViewRowState.Added
| DataViewRowState.ModifiedCurrent;
// Print those rows. Output = "Hello" "World";
PrintView(dataView, "ModifiedCurrent and Added");
// Set filter to display on originals of modified rows.
dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
PrintView(dataView, "ModifiedOriginal");
// Delete three rows.
dataTable.Rows[1].Delete();
dataTable.Rows[2].Delete();
dataTable.Rows[3].Delete();
// Set the RowStateFilter to display only Added and modified rows.
dataView.RowStateFilter = DataViewRowState.Deleted;
PrintView(dataView, "Deleted");
//Set filter to display only current.
dataView.RowStateFilter = DataViewRowState.CurrentRows;
PrintView(dataView, "Current");
// Set filter to display only unchanged rows.
dataView.RowStateFilter = DataViewRowState.Unchanged;
PrintView(dataView, "Unchanged");
// Set filter to display only original rows.
dataView.RowStateFilter = DataViewRowState.OriginalRows;
PrintView(dataView, "OriginalRows");
}
static private void PrintView(DataView dataView, string label)
{
Console.WriteLine("\n" + label);
for (int i = 0; i < dataView.Count; i++)
{
Console.WriteLine(dataView[i]["dataColumn"]);
}
}