DataRowView Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a customized view of a DataRow.
public ref class DataRowView : System::ComponentModel::ICustomTypeDescriptor, System::ComponentModel::IDataErrorInfo, System::ComponentModel::IEditableObject, System::ComponentModel::INotifyPropertyChanged
public ref class DataRowView : System::ComponentModel::ICustomTypeDescriptor, System::ComponentModel::IDataErrorInfo, System::ComponentModel::IEditableObject
public class DataRowView : System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IDataErrorInfo, System.ComponentModel.IEditableObject, System.ComponentModel.INotifyPropertyChanged
public class DataRowView : System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IDataErrorInfo, System.ComponentModel.IEditableObject
type DataRowView = class
interface ICustomTypeDescriptor
interface IDataErrorInfo
interface IEditableObject
interface INotifyPropertyChanged
type DataRowView = class
interface ICustomTypeDescriptor
interface IEditableObject
interface IDataErrorInfo
type DataRowView = class
interface ICustomTypeDescriptor
interface IEditableObject
interface IDataErrorInfo
interface INotifyPropertyChanged
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject, INotifyPropertyChanged
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject
- Inheritance
-
DataRowView
- Implements
The following example uses the RowVersion property to determine the state of a row in the DataRowView. (See RowFilter for another example using DataRowView.)
private static void DemonstrateRowVersion()
{
// Create a DataTable with one column.
DataTable table = new DataTable("Table");
DataColumn column = new DataColumn("Column");
table.Columns.Add(column);
// Add ten rows.
DataRow row;
for (int i = 0; i < 10; i++)
{
row = table.NewRow();
row["Column"] = "item " + i;
table.Rows.Add(row);
}
table.AcceptChanges();
// Create a DataView with the table.
DataView view = 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 |
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");
}
private static void PrintView(DataView view, string label)
{
Console.WriteLine("\n" + label);
for (int i = 0; i < view.Count; i++)
{
Console.WriteLine(view[i]["Column"]);
Console.WriteLine("DataViewRow.RowVersion: {0}",
view[i].RowVersion);
}
}
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
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.
Data |
Gets the DataView to which this row belongs. |
Is |
Indicates whether the row is in edit mode. |
Is |
Indicates whether a DataRowView is new. |
Item[Int32] |
Gets or sets a value in a specified column. |
Item[String] |
Gets or sets a value in a specified column. |
Row |
Gets the DataRow being viewed. |
Row |
Gets the current version description of the DataRow. |
Begin |
Begins an edit procedure. |
Cancel |
Cancels an edit procedure. |
Create |
Returns a DataView for the child DataTable with the specified DataRelation and parent. |
Create |
Returns a DataView for the child DataTable with the specified child DataRelation. |
Create |
Returns a DataView for the child DataTable with the specified DataRelation name and parent. |
Create |
Returns a DataView for the child DataTable with the specified child DataRelation name. |
Delete() |
Deletes a row. |
End |
Commits changes to the underlying DataRow and ends the editing session that was begun with BeginEdit(). Use CancelEdit() to discard the changes made to the DataRow. |
Equals(Object) |
Gets a value indicating whether the current DataRowView is identical to the specified object. |
Get |
Returns the hash code of the DataRow object. |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Property |
Event that is raised when a DataRowView property is changed. |
ICustom |
Returns a collection of custom attributes for this instance of a component. |
ICustom |
Returns the class name of this instance of a component. |
ICustom |
Returns the name of this instance of a component. |
ICustom |
Returns a type converter for this instance of a component. |
ICustom |
Returns the default event for this instance of a component. |
ICustom |
Returns the default property for this instance of a component. |
ICustom |
Returns an editor of the specified type for this instance of a component. |
ICustom |
Returns the events for this instance of a component. |
ICustom |
Returns the events for this instance of a component with specified attributes. |
ICustom |
Returns the properties for this instance of a component. |
ICustom |
Returns the properties for this instance of a component with specified attributes. |
ICustom |
Returns an object that contains the property described by the specified property descriptor. |
IData |
Gets a message that describes any validation errors for the object. |
IData |
Gets the error message for the property with the given name. |
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
This type is safe for multithreaded read operations. You must synchronize any write operations.
.NET feedback
.NET is an open source project. Select a link to provide feedback: