Assembly : System.Data (dans system.data.dll)
SyntaxePublic Class DataRowView Implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
Dim instance As DataRowView
public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
public ref class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
public class DataRowView implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
public class DataRowView implements ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged
NotesLorsque les données sont affichées, comme dans un contrôle DataGrid, seule une version de chaque ligne peut être affichée. La ligne affichée est DataRowView.
DataRowView peut posséder un des quatre états de versions suivants : Default, Original, Current et Proposed.
Lorsque vous avez appelé BeginEdit sur DataRow, toute valeur modifiée devient la valeur Proposed. Tant que CancelEdit ou EndEdit n'est pas appelé, la ligne possède une version Original et une version Proposed. Si CancelEdit est appelé, la version proposée est ignorée et la valeur Original est rétablie. Si EndEdit est appelé, DataRowView ne dispose plus de version Proposed. En revanche, la valeur proposée devient la valeur actuelle. Les valeurs par défaut ne sont disponibles que sur les lignes possédant des colonnes dont des valeurs par défaut sont définies.
ExempleL'exemple suivant utilise la propriété RowVersion pour déterminer l'état d'une ligne dans 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
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); } }
Sécurité des threadsCe type est sécurisé pour les opérations de lecture multithread. Vous devez synchroniser les opérations d'écriture.
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ