Partager via


DataRowView Classe

Définition

Représente une vue personnalisée d’un 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
Héritage
DataRowView
Implémente

Exemples

L’exemple suivant utilise la RowVersion propriété pour déterminer l’état d’une ligne dans le DataRowView. (Consultez RowFilter un autre exemple utilisant 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

Remarques

Chaque fois que les données sont affichées, comme dans un DataGrid contrôle, une seule version de chaque ligne peut être affichée. La ligne affichée est un DataRowView.

Un DataRowView peut avoir l’un des quatre états de version différents : Default, , OriginalCurrent, et Proposed.

Après l’appel BeginEdit sur un DataRow, toute valeur modifiée devient la Proposed valeur. Jusqu’à ce que l’une ou l’autre CancelEdit soit appelée, la ligne a une Original version et une Proposed version.EndEdit Si CancelEdit elle est appelée, la version proposée est ignorée et la valeur est rétablie Original. Si EndEdit elle est appelée, la DataRowView version n’a Proposed plus de version ; à la place, la valeur proposée devient la valeur actuelle. Les valeurs par défaut sont disponibles uniquement sur les lignes qui ont des colonnes avec des valeurs par défaut définies.

Propriétés

Nom Description
DataView

Obtient l’objet DataView auquel appartient cette ligne.

IsEdit

Indique si la ligne est en mode édition.

IsNew

Indique si un DataRowView élément est nouveau.

Item[Int32]

Obtient ou définit une valeur dans une colonne spécifiée.

Item[String]

Obtient ou définit une valeur dans une colonne spécifiée.

Row

Obtient l’affichage DataRow .

RowVersion

Obtient la description de la version actuelle du DataRow.

Méthodes

Nom Description
BeginEdit()

Commence une procédure de modification.

CancelEdit()

Annule une procédure de modification.

CreateChildView(DataRelation, Boolean)

Retourne une DataView valeur pour l’enfant DataTable avec le parent et le parent spécifiés DataRelation .

CreateChildView(DataRelation)

Retourne une DataView valeur pour l’enfant DataTable avec l’enfant DataRelationspécifié.

CreateChildView(String, Boolean)

Retourne un DataView enfant DataTable portant le nom et le parent spécifiés DataRelation .

CreateChildView(String)

Retourne une DataView valeur pour l’enfant DataTable portant le nom enfant DataRelation spécifié.

Delete()

Supprime une ligne.

EndEdit()

Valide les modifications apportées au sous-jacent DataRow et met fin à la session d’édition qui a été démarrée avec BeginEdit(). Permet CancelEdit() d’ignorer les modifications apportées à l’objet DataRow.

Equals(Object)

Obtient une valeur indiquant si le courant DataRowView est identique à l’objet spécifié.

GetHashCode()

Retourne le code de hachage de l’objet DataRow .

GetType()

Obtient la Type de l’instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Objectactuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l’objet actuel.

(Hérité de Object)

Événements

Nom Description
PropertyChanged

Événement déclenché lorsqu’une DataRowView propriété est modifiée.

Implémentations d’interfaces explicites

Nom Description
ICustomTypeDescriptor.GetAttributes()

Retourne une collection d’attributs personnalisés pour cette instance d’un composant.

ICustomTypeDescriptor.GetClassName()

Retourne le nom de classe de cette instance d’un composant.

ICustomTypeDescriptor.GetComponentName()

Retourne le nom de cette instance d’un composant.

ICustomTypeDescriptor.GetConverter()

Retourne un convertisseur de type pour cette instance d’un composant.

ICustomTypeDescriptor.GetDefaultEvent()

Retourne l’événement par défaut pour cette instance d’un composant.

ICustomTypeDescriptor.GetDefaultProperty()

Retourne la propriété par défaut pour cette instance d’un composant.

ICustomTypeDescriptor.GetEditor(Type)

Retourne un éditeur du type spécifié pour cette instance d’un composant.

ICustomTypeDescriptor.GetEvents()

Retourne les événements de cette instance d’un composant.

ICustomTypeDescriptor.GetEvents(Attribute[])

Retourne les événements de cette instance d’un composant avec des attributs spécifiés.

ICustomTypeDescriptor.GetProperties()

Retourne les propriétés de cette instance d’un composant.

ICustomTypeDescriptor.GetProperties(Attribute[])

Retourne les propriétés de cette instance d’un composant avec des attributs spécifiés.

ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)

Retourne un objet qui contient la propriété décrite par le descripteur de propriété spécifié.

IDataErrorInfo.Error

Obtient un message qui décrit les erreurs de validation de l’objet.

IDataErrorInfo.Item[String]

Obtient le message d’erreur de la propriété portant le nom donné.

S’applique à

Cohérence de thread

Ce type est sécurisé pour les opérations de lecture multithread. Vous devez synchroniser toutes les opérations d’écriture.

Voir aussi