DataRowView Class
Assembly: System.Data (in system.data.dll)
'Declaration Public Class DataRowView Implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged 'Usage Dim instance As DataRowView
public class DataRowView implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
public class DataRowView implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
Not applicable.
Whenever data is displayed, such as in a DataGrid control, only one version of each row can be displayed. The displayed row is a DataRowView.
A DataRowView can have one of four different version states: Default, Original, Current, and Proposed.
After invoking BeginEdit on a DataRow, any edited value becomes the Proposed value. Until either CancelEdit or EndEdit is invoked, the row has an Original and a Proposed version. If CancelEdit is invoked, the proposed version is discarded, and the value reverts to Original. If EndEdit is invoked, the DataRowView no longer has a Proposed version; instead, the proposed value becomes the current value. Default values are available only on rows that have columns with default values defined.
The following example uses the RowVersion property to determine the state of a row in the DataRowView.
Private Sub DemonstrateRowVersion() Dim i As Integer ' Create a DataTable with one column. Dim table As New DataTable("Table") Dim column As New DataColumn("Column") table.Columns.Add(column) ' Add ten rows. Dim row As DataRow For i = 0 To 9 row = table.NewRow() row("Column") = "item " + i.ToString() table.Rows.Add(row) Next i table.AcceptChanges() ' Create a DataView with the table. Dim view As New DataView(table) ' Change one row's value: table.Rows(1)("Column") = "Hello" ' Add one row: row = table.NewRow() row("Column") = "World" table.Rows.Add(row) ' Set the RowStateFilter to display only added and modified rows. view.RowStateFilter = _ DataViewRowState.Added Or DataViewRowState.ModifiedCurrent ' Print those rows. Output includes "Hello" and "World". PrintView(view, "ModifiedCurrent and Added") ' Set filter to display only originals of modified rows. view.RowStateFilter = DataViewRowState.ModifiedOriginal PrintView(view, "ModifiedOriginal") ' Delete three rows. table.Rows(1).Delete() table.Rows(2).Delete() table.Rows(3).Delete() ' Set the RowStateFilter to display only deleted rows. view.RowStateFilter = DataViewRowState.Deleted PrintView(view, "Deleted") ' Set filter to display only current rows. view.RowStateFilter = DataViewRowState.CurrentRows PrintView(view, "Current") ' Set filter to display only unchanged rows. view.RowStateFilter = DataViewRowState.Unchanged PrintView(view, "Unchanged") ' Set filter to display only original rows. ' Current values of unmodified rows are also returned. view.RowStateFilter = DataViewRowState.OriginalRows PrintView(view, "OriginalRows") End Sub Private Sub PrintView(ByVal view As DataView, ByVal label As String) Console.WriteLine(ControlChars.Cr + label) Dim i As Integer For i = 0 To view.Count - 1 Console.WriteLine(view(i)("Column")) Console.WriteLine("DataRowView.RowVersion: {0}", _ view(i).RowVersion) Next i End Sub
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.