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 usata la RowVersion proprietà per determinare lo stato di una riga in DataRowView. Vedere RowFilter per un altro esempio usando 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

Commenti

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

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

Dopo aver richiamato BeginEdit su un DataRow, qualsiasi valore modificato diventa il Proposed valore. CancelEdit Fino a quando non viene richiamata o EndEdit richiamata, la riga ha una Original Proposed versione e. Se CancelEdit viene richiamato, la versione proposta viene eliminata e il valore viene ripristinato in 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 in righe con colonne con valori predefiniti definiti.

Proprietà

DataView

Ottiene l'oggetto DataView cui appartiene questa 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 dell'oggetto DataRow.

Metodi

BeginEdit()

Dà inizio a una routine di modifica.

CancelEdit()

Annulla una routine di modifica.

CreateChildView(DataRelation)

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

CreateChildView(DataRelation, Boolean)

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

CreateChildView(String)

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

CreateChildView(String, Boolean)

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

Delete()

Elimina una riga.

EndEdit()

Esegue il commit delle modifiche al DataRow sottostante e termina la sessione di modifica iniziata con BeginEdit(). Utilizzare CancelEdit() per annullare le modifiche apportate a DataRow.

Equals(Object)

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

GetHashCode()

Restituisce il codice hash dell'oggetto DataRow.

GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Eventi

PropertyChanged

Evento generato quando viene modificata una proprietà DataRowView.

Implementazioni dell'interfaccia esplicita

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 gli 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 gli 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