DataRowView Класс
Определение
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
- Наследование
-
DataRowView
- Реализации
Примеры
В следующем примере свойство используется RowVersion для определения состояния строки в DataRowView .The following example uses the RowVersion property to determine the state of a row in the DataRowView. (См RowFilter . другой пример с помощью 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
Комментарии
При каждом отображении данных, например в DataGrid элементе управления, можно отобразить только одну версию каждой строки.Whenever data is displayed, such as in a DataGrid control, only one version of each row can be displayed. Отображаемая строка — DataRowView .The displayed row is a DataRowView.
DataRowViewМожет иметь одно из четырех различных состояний версий: Default
, Original
, Current
и Proposed
.A DataRowView can have one of four different version states: Default
, Original
, Current
, and Proposed
.
После вызова BeginEdit в DataRow любое редактируемое значение преобразуется в Proposed
значение.After invoking BeginEdit on a DataRow, any edited value becomes the Proposed
value. До CancelEdit EndEdit вызова метода или, строка имеет значение Original
и Proposed
версию.Until either CancelEdit or EndEdit is invoked, the row has an Original
and a Proposed
version. Если CancelEdit вызывается метод, предлагаемая версия отбрасывается, а значение возвращается к Original
.If CancelEdit is invoked, the proposed version is discarded, and the value reverts to Original
. Если EndEdit вызывается метод, он DataRowView больше не имеет Proposed
версии; вместо этого предложенное значение становится текущим значением.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.
Свойства
DataView |
Получает объект DataView, которому принадлежит эта строка.Gets the DataView to which this row belongs. |
IsEdit |
Определяет, находится ли строка в режиме изменения.Indicates whether the row is in edit mode. |
IsNew |
Указывает, является ли новым объект DataRowView.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 |
Получает просматриваемый объект DataRow.Gets the DataRow being viewed. |
RowVersion |
Получает описание текущей версии объекта DataRow.Gets the current version description of the DataRow. |
Методы
BeginEdit() |
Начинает процедуру изменения.Begins an edit procedure. |
CancelEdit() |
Отменяет процедуру изменения.Cancels an edit procedure. |
CreateChildView(DataRelation) |
Возвращает DataView для дочернего объекта DataTable с указанным дочерним объектом DataRelation.Returns a DataView for the child DataTable with the specified child DataRelation. |
CreateChildView(DataRelation, Boolean) |
Возвращает DataView для дочернего объекта DataTable с указанным DataRelation и родительским объектом.Returns a DataView for the child DataTable with the specified DataRelation and parent. |
CreateChildView(String) |
Возвращает DataView для дочернего объекта DataTable с указанным именем дочернего объекта DataRelation.Returns a DataView for the child DataTable with the specified child DataRelation name. |
CreateChildView(String, Boolean) |
Возвращает DataView для дочернего объекта DataTable с указанным именем DataRelation и родительским объектом.Returns a DataView for the child DataTable with the specified DataRelation name and parent. |
Delete() |
Удаляет строку.Deletes a row. |
EndEdit() |
Фиксирует изменения в базовом DataRow и заканчивает сеанс редактирования, который был начат с BeginEdit().Commits changes to the underlying DataRow and ends the editing session that was begun with BeginEdit(). Используйте метод CancelEdit() для отмены изменений, внесенных в объект DataRow.Use CancelEdit() to discard the changes made to the DataRow. |
Equals(Object) |
Возвращает значение,указывающее, идентичен ли текущий объект DataRowView указанному объекту.Gets a value indicating whether the current DataRowView is identical to the specified object. |
GetHashCode() |
Возвращает хэш-код объекта DataRow.Returns the hash code of the DataRow object. |
GetType() |
Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance. (Унаследовано от Object) |
MemberwiseClone() |
Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object. (Унаследовано от Object) |
ToString() |
Возвращает строку, представляющую текущий объект.Returns a string that represents the current object. (Унаследовано от Object) |
События
PropertyChanged |
Событие, которое возникло, когда свойство DataRowView было изменено.Event that is raised when a DataRowView property is changed. |
Явные реализации интерфейса
ICustomTypeDescriptor.GetAttributes() |
Возвращает коллекцию настраиваемых атрибутов для этого экземпляра компонента.Returns a collection of custom attributes for this instance of a component. |
ICustomTypeDescriptor.GetClassName() |
Возвращает имя класса для этого экземпляра компонента.Returns the class name of this instance of a component. |
ICustomTypeDescriptor.GetComponentName() |
Возвращает имя этого экземпляра компонента.Returns the name of this instance of a component. |
ICustomTypeDescriptor.GetConverter() |
Возвращает преобразователь типов для этого экземпляра компонента.Returns a type converter for this instance of a component. |
ICustomTypeDescriptor.GetDefaultEvent() |
Возвращает событие по умолчанию для этого экземпляра компонента.Returns the default event for this instance of a component. |
ICustomTypeDescriptor.GetDefaultProperty() |
Возвращает свойство по умолчанию для этого экземпляра компонента.Returns the default property for this instance of a component. |
ICustomTypeDescriptor.GetEditor(Type) |
Возвращает редактор заданного типа для этого экземпляра компонента.Returns an editor of the specified type for this instance of a component. |
ICustomTypeDescriptor.GetEvents() |
Возвращает события для этого экземпляра компонента.Returns the events for this instance of a component. |
ICustomTypeDescriptor.GetEvents(Attribute[]) |
Возвращает события для этого экземпляра компонента с заданными атрибутами.Returns the events for this instance of a component with specified attributes. |
ICustomTypeDescriptor.GetProperties() |
Возвращает свойства для этого экземпляра компонента.Returns the properties for this instance of a component. |
ICustomTypeDescriptor.GetProperties(Attribute[]) |
Возвращает свойства для этого экземпляра компонента с заданными атрибутами.Returns the properties for this instance of a component with specified attributes. |
ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor) |
Возвращает объект, содержащий свойство, описываемое заданным дескриптором свойства.Returns an object that contains the property described by the specified property descriptor. |
IDataErrorInfo.Error |
Получает сообщение, описывающее все ошибки проверки объекта.Gets a message that describes any validation errors for the object. |
IDataErrorInfo.Item[String] |
Возвращает сообщение об ошибке для свойства с заданным именем.Gets the error message for the property with the given name. |
Применяется к
Потокобезопасность
Этот тип является надежным для многопоточных операций чтения.This type is safe for multithreaded read operations. Необходимо синхронизировать любые операции записи.You must synchronize any write operations.