DataRowView Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Representa uma vista personalizada de um DataRow.
public ref class DataRowView : System::ComponentModel::ICustomTypeDescriptor, System::ComponentModel::IDataErrorInfo, System::ComponentModel::IEditableObject
public ref 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
public class DataRowView : System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IDataErrorInfo, System.ComponentModel.IEditableObject, System.ComponentModel.INotifyPropertyChanged
type DataRowView = class
interface ICustomTypeDescriptor
interface IEditableObject
interface IDataErrorInfo
type DataRowView = class
interface ICustomTypeDescriptor
interface IEditableObject
interface IDataErrorInfo
interface INotifyPropertyChanged
type DataRowView = class
interface ICustomTypeDescriptor
interface IDataErrorInfo
interface IEditableObject
interface INotifyPropertyChanged
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject
Public Class DataRowView
Implements ICustomTypeDescriptor, IDataErrorInfo, IEditableObject, INotifyPropertyChanged
- Herança
-
DataRowView
- Implementações
Exemplos
O exemplo seguinte usa a RowVersion propriedade para determinar o estado de uma linha no DataRowView. (Ver RowFilter outro exemplo 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
Observações
Sempre que dados são exibidos, como num DataGrid controlo, apenas uma versão de cada linha pode ser apresentada. A linha apresentada é um DataRowView.
A DataRowView pode ter um de quatro estados de versão diferentes: Default, Original, Current, e Proposed.
Após invocar BeginEdit em um DataRow, qualquer valor editado torna-se o Proposed valor. Até que seja invocado um ou CancelEditEndEdit outro, a série tem uma Original versão e uma Proposed versão. Se CancelEdit for invocado, a versão proposta é descartada e o valor reverte para Original. Se EndEdit for invocado, o DataRowView já não tem uma Proposed versão; em vez disso, o valor proposto torna-se o valor atual. Os valores por defeito estão disponíveis apenas em linhas que tenham colunas com valores definidos.
Propriedades
| Name | Description |
|---|---|
| DataView |
Percebe a DataView que esta fila pertence. |
| IsEdit |
Indica se a linha está em modo de edição. |
| IsNew |
Indica se a DataRowView é novo. |
| Item[Int32] |
Recebe ou define um valor numa coluna especificada. |
| Item[String] |
Recebe ou define um valor numa coluna especificada. |
| Row |
Faz com que o DataRow ser seja visto. |
| RowVersion |
Obtém a descrição da versão atual do DataRow. |
Métodos
| Name | Description |
|---|---|
| BeginEdit() |
Inicia um processo de edição. |
| CancelEdit() |
Cancela um procedimento de edição. |
| CreateChildView(DataRelation, Boolean) |
Devolve um DataView para a criança DataTable com o especificado DataRelation e o progenitor. |
| CreateChildView(DataRelation) |
Devolve a DataView para a criança DataTable com a criança DataRelationespecificada. |
| CreateChildView(String, Boolean) |
Devolve a DataView para a criança DataTable com o nome e progenitor especificados DataRelation . |
| CreateChildView(String) |
Devolve a DataView para a criança DataTable com o nome especificado DataRelation . |
| Delete() |
Apaga uma linha. |
| EndEdit() |
Faz commit de alterações ao subjacente DataRow e termina a sessão de edição iniciada com BeginEdit(). Use CancelEdit() para descartar as alterações feitas ao DataRow. |
| Equals(Object) |
Obtém um valor que indica se a corrente DataRowView é idêntica ao objeto especificado. |
| GetHashCode() |
Devolve o código de hash do DataRow objeto. |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |
evento
| Name | Description |
|---|---|
| PropertyChanged |
Evento que é levantado quando uma DataRowView propriedade é alterada. |
Implementações de Interface Explícita
| Name | Description |
|---|---|
| ICustomTypeDescriptor.GetAttributes() |
Devolve uma coleção de atributos personalizados para esta instância de um componente. |
| ICustomTypeDescriptor.GetClassName() |
Devolve o nome da classe desta instância de um componente. |
| ICustomTypeDescriptor.GetComponentName() |
Devolve o nome desta instância de um componente. |
| ICustomTypeDescriptor.GetConverter() |
Devolve um conversor de tipos para esta instância de um componente. |
| ICustomTypeDescriptor.GetDefaultEvent() |
Devolve o evento predefinido para esta instância de um componente. |
| ICustomTypeDescriptor.GetDefaultProperty() |
Devolve a propriedade padrão para esta instância de um componente. |
| ICustomTypeDescriptor.GetEditor(Type) |
Devolve um editor do tipo especificado para esta instância de um componente. |
| ICustomTypeDescriptor.GetEvents() |
Devolve os eventos para esta instância de um componente. |
| ICustomTypeDescriptor.GetEvents(Attribute[]) |
Devolve os eventos para esta instância de um componente com atributos especificados. |
| ICustomTypeDescriptor.GetProperties() |
Devolve as propriedades para esta instância de um componente. |
| ICustomTypeDescriptor.GetProperties(Attribute[]) |
Devolve as propriedades para esta instância de um componente com atributos especificados. |
| ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor) |
Devolve um objeto que contém a propriedade descrita pelo descritor de propriedades especificado. |
| IDataErrorInfo.Error |
Recebe uma mensagem que descreve quaisquer erros de validação para o objeto. |
| IDataErrorInfo.Item[String] |
Recebe a mensagem de erro da propriedade com o nome próprio. |
Aplica-se a
Segurança de Thread
Este tipo é seguro para operações de leitura multithread. Tem de sincronizar quaisquer operações de escrita.