Condividi tramite


DataRowView Classe

Definizione

Rappresenta una visualizzazione personalizzata di un oggetto 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
Ereditarietà
DataRowView
Implementazioni

Esempio

Nell'esempio seguente viene utilizzata la RowVersion proprietà per determinare lo stato di una riga in DataRowView. Per un altro esempio, vedere RowFilterDataRowView.)

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

Commenti

Ogni volta che vengono visualizzati dati, ad esempio in un DataGrid controllo, è possibile visualizzare una sola versione di ogni riga. La riga visualizzata è un oggetto DataRowView.

Un DataRowView può avere uno dei quattro stati di versione diversi: Default, Original, Currente Proposed.

Dopo aver richiamato BeginEdit su , DataRowqualsiasi valore modificato diventa il Proposed valore . CancelEdit Fino a quando non viene richiamato o EndEdit , la riga ha una Original versione e .Proposed Se CancelEdit viene richiamato, la versione proposta viene rimossa e il valore viene ripristinato su Original. Se EndEdit viene richiamato, l'oggetto DataRowView non ha più una Proposed versione. Il valore proposto diventa invece il valore corrente. I valori predefiniti sono disponibili solo nelle righe con colonne con valori predefiniti definiti.

Proprietà

Nome Descrizione
DataView

Ottiene l'oggetto DataView a cui appartiene la riga.

IsEdit

Indica se la riga è in modalità di modifica.

IsNew

Indica se un oggetto DataRowView è nuovo.

Item[Int32]

Ottiene o imposta un valore in una colonna specificata.

Item[String]

Ottiene o imposta un valore in una colonna specificata.

Row

Ottiene l'oggetto DataRow visualizzato.

RowVersion

Ottiene la descrizione della versione corrente di DataRow.

Metodi

Nome Descrizione
BeginEdit()

Avvia una procedura di modifica.

CancelEdit()

Annulla una procedura di modifica.

CreateChildView(DataRelation, Boolean)

Restituisce un oggetto DataView per l'elemento figlio DataTable con l'oggetto padre e specificato DataRelation .

CreateChildView(DataRelation)

Restituisce un oggetto DataView per l'elemento figlio DataTable con l'oggetto figlio DataRelationspecificato.

CreateChildView(String, Boolean)

Restituisce un oggetto DataView per l'elemento figlio DataTable con il nome e l'elemento padre specificati DataRelation .

CreateChildView(String)

Restituisce un oggetto DataView per l'elemento figlio DataTable con il nome figlio DataRelation specificato.

Delete()

Elimina una riga.

EndEdit()

Esegue il commit delle modifiche all'oggetto sottostante DataRow e termina la sessione di modifica iniziata con BeginEdit(). Usare CancelEdit() per rimuovere le modifiche apportate all'oggetto DataRow.

Equals(Object)

Ottiene un valore che indica se l'oggetto corrente DataRowView è identico all'oggetto specificato.

GetHashCode()

Restituisce il codice hash dell'oggetto DataRow .

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Eventi

Nome Descrizione
PropertyChanged

Evento generato quando viene modificata una DataRowView proprietà.

Implementazioni dell'interfaccia esplicita

Nome Descrizione
ICustomTypeDescriptor.GetAttributes()

Restituisce una raccolta di attributi personalizzati per questa istanza di un componente.

ICustomTypeDescriptor.GetClassName()

Restituisce il nome della classe di questa istanza di un componente.

ICustomTypeDescriptor.GetComponentName()

Restituisce il nome di questa istanza di un componente.

ICustomTypeDescriptor.GetConverter()

Restituisce un convertitore di tipi per questa istanza di un componente.

ICustomTypeDescriptor.GetDefaultEvent()

Restituisce l'evento predefinito per questa istanza di un componente.

ICustomTypeDescriptor.GetDefaultProperty()

Restituisce la proprietà predefinita per questa istanza di un componente.

ICustomTypeDescriptor.GetEditor(Type)

Restituisce un editor del tipo specificato per questa istanza di un componente.

ICustomTypeDescriptor.GetEvents()

Restituisce gli eventi per questa istanza di un componente.

ICustomTypeDescriptor.GetEvents(Attribute[])

Restituisce gli eventi per questa istanza di un componente con attributi specificati.

ICustomTypeDescriptor.GetProperties()

Restituisce le proprietà per questa istanza di un componente.

ICustomTypeDescriptor.GetProperties(Attribute[])

Restituisce le proprietà per questa istanza di un componente con attributi specificati.

ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)

Restituisce un oggetto che contiene la proprietà descritta dal descrittore di proprietà specificato.

IDataErrorInfo.Error

Ottiene un messaggio che descrive eventuali errori di convalida per l'oggetto .

IDataErrorInfo.Item[String]

Ottiene il messaggio di errore per la proprietà con il nome specificato.

Si applica a

Thread safety

Questo tipo è sicuro per le operazioni di lettura multithreading. È necessario sincronizzare tutte le operazioni di scrittura.

Vedi anche