DataView クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
public ref class DataView : System::ComponentModel::MarshalByValueComponent, System::Collections::IList, System::ComponentModel::IBindingListView, System::ComponentModel::ISupportInitialize, System::ComponentModel::ISupportInitializeNotification, System::ComponentModel::ITypedList
public ref class DataView : System::ComponentModel::MarshalByValueComponent, System::Collections::IList, System::ComponentModel::IBindingList, System::ComponentModel::ISupportInitialize, System::ComponentModel::ITypedList
public ref class DataView : System::ComponentModel::MarshalByValueComponent, System::Collections::IList, System::ComponentModel::IBindingListView, System::ComponentModel::ISupportInitializeNotification, System::ComponentModel::ITypedList
public ref class DataView : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IBindingListView, System::ComponentModel::ISupportInitializeNotification, System::ComponentModel::ITypedList
public class DataView : System.ComponentModel.MarshalByValueComponent, System.Collections.IList, System.ComponentModel.IBindingListView, System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.ITypedList
public class DataView : System.ComponentModel.MarshalByValueComponent, System.Collections.IList, System.ComponentModel.IBindingList, System.ComponentModel.ISupportInitialize, System.ComponentModel.ITypedList
public class DataView : System.ComponentModel.MarshalByValueComponent, System.Collections.IList, System.ComponentModel.IBindingListView, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.ITypedList
public class DataView : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IBindingListView, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.ITypedList
type DataView = class
inherit MarshalByValueComponent
interface ICollection
interface IEnumerable
interface IList
interface IBindingList
interface IBindingListView
interface ISupportInitialize
interface ISupportInitializeNotification
interface ITypedList
type DataView = class
inherit MarshalByValueComponent
interface IBindingList
interface IList
interface ICollection
interface IEnumerable
interface ITypedList
interface ISupportInitialize
type DataView = class
inherit MarshalByValueComponent
interface IBindingListView
interface IBindingList
interface IList
interface ICollection
interface IEnumerable
interface ITypedList
interface ISupportInitializeNotification
interface ISupportInitialize
type DataView = class
inherit MarshalByValueComponent
interface IBindingListView
interface ITypedList
interface ISupportInitializeNotification
interface IBindingList
interface IList
interface ICollection
interface IEnumerable
interface ISupportInitialize
Public Class DataView
Inherits MarshalByValueComponent
Implements IBindingListView, IList, ISupportInitialize, ISupportInitializeNotification, ITypedList
Public Class DataView
Inherits MarshalByValueComponent
Implements IBindingList, IList, ISupportInitialize, ITypedList
Public Class DataView
Inherits MarshalByValueComponent
Implements IBindingListView, IList, ISupportInitializeNotification, ITypedList
Public Class DataView
Inherits MarshalByValueComponent
Implements IBindingListView, ISupportInitializeNotification, ITypedList
- 継承
- 実装
例
次の例では、1 つの列と 5 行の単一 DataTable の列を作成します。 2 つの DataView オブジェクトが作成され、テーブル データの RowStateFilter 異なるビューを表示するようにそれぞれに設定されます。 その後、値が出力されます。
using System;
using System.Xml;
using System.Data;
using System.Data.Common;
using System.Windows.Forms;
public class Form1: Form
{
protected DataSet DataSet1;
protected DataGrid dataGrid1;
private void DemonstrateDataView()
{
// Create one DataTable with one column.
DataTable table = new DataTable("table");
DataColumn colItem = new DataColumn("item",
Type.GetType("System.String"));
table.Columns.Add(colItem);
// Add five items.
DataRow NewRow;
for(int i = 0; i <5; i++)
{
NewRow = table.NewRow();
NewRow["item"] = "Item " + i;
table.Rows.Add(NewRow);
}
// Change the values in the table.
table.AcceptChanges();
table.Rows[0]["item"]="cat";
table.Rows[1]["item"] = "dog";
// Create two DataView objects with the same table.
DataView firstView = new DataView(table);
DataView secondView = new DataView(table);
// Print current table values.
PrintTableOrView(table,"Current Values in Table");
// Set first DataView to show only modified
// versions of original rows.
firstView.RowStateFilter=DataViewRowState.ModifiedOriginal;
// Print values.
PrintTableOrView(firstView,"First DataView: ModifiedOriginal");
// Add one New row to the second view.
DataRowView rowView;
rowView=secondView.AddNew();
rowView["item"] = "fish";
// Set second DataView to show modified versions of
// current rows, or New rows.
secondView.RowStateFilter=DataViewRowState.ModifiedCurrent
| DataViewRowState.Added;
// Print modified and Added rows.
PrintTableOrView(secondView,
"Second DataView: ModifiedCurrent | Added");
}
private void PrintTableOrView(DataTable table, string label)
{
// This function prints values in the table or DataView.
Console.WriteLine("\n" + label);
for(int i = 0; i<table.Rows.Count;i++)
{
Console.WriteLine("\table" + table.Rows[i]["item"]);
}
Console.WriteLine();
}
private void PrintTableOrView(DataView view, string label)
{
// This overload prints values in the table or DataView.
Console.WriteLine("\n" + label);
for(int i = 0; i<view.Count;i++)
{
Console.WriteLine("\table" + view[i]["item"]);
}
Console.WriteLine();
}
}
Private Sub DemonstrateDataView()
' Create one DataTable with one column.
Dim table As New DataTable("table")
Dim colItem As New DataColumn("item", _
Type.GetType("System.String"))
table.Columns.Add(colItem)
' Add five items.
Dim NewRow As DataRow
Dim i As Integer
For i = 0 To 4
NewRow = table.NewRow()
NewRow("item") = "Item " & i
table.Rows.Add(NewRow)
Next
table.AcceptChanges()
' Create two DataView objects with the same table.
Dim firstView As New DataView(table)
Dim secondView As New DataView(table)
' Change the values in the table.
table.Rows(0)("item") = "cat"
table.Rows(1)("item") = "dog"
' Print current table values.
PrintTableOrView(table, "Current Values in Table")
' Set first DataView to show only modified versions of original rows.
firstView.RowStateFilter = DataViewRowState.ModifiedOriginal
' Print values.
PrintTableOrView(firstView, "First DataView: ModifiedOriginal")
' Add one New row to the second view.
Dim rowView As DataRowView
rowView = secondView.AddNew()
rowView("item") = "fish"
' Set second DataView to show modified versions of
' current rows, or New rows.
secondView.RowStateFilter = DataViewRowState.ModifiedCurrent _
Or DataViewRowState.Added
' Print modified and Added rows.
PrintTableOrView(secondView, _
"Second DataView: ModifiedCurrent or Added")
End Sub
Overloads Private Sub PrintTableOrView( _
ByVal view As DataView, ByVal label As String)
Console.WriteLine(label)
Dim i As Integer
For i = 0 To view.count - 1
Console.WriteLine(view(i)("item"))
Next
Console.WriteLine()
End Sub
Overloads Private Sub PrintTableOrView( _
ByVal table As DataTable, ByVal label As String)
Console.WriteLine(label)
Dim i As Integer
For i = 0 To table.Rows.Count - 1
Console.WriteLine(table.Rows(i)("item"))
Next
Console.WriteLine()
End Sub
次の例では、DataViewLINQ to DataSet クエリによって合計で並べ替えられたオンライン注文を作成します。
DataTable orders = dataSet.Tables["SalesOrderHeader"];
EnumerableRowCollection<DataRow> query =
from order in orders.AsEnumerable()
where order.Field<bool>("OnlineOrderFlag") == true
orderby order.Field<decimal>("TotalDue")
select order;
DataView view = query.AsDataView();
bindingSource1.DataSource = view;
Dim orders As DataTable = dataSet.Tables("SalesOrderHeader")
Dim query = _
From order In orders.AsEnumerable() _
Where order.Field(Of Boolean)("OnlineOrderFlag") = True _
Order By order.Field(Of Decimal)("TotalDue") _
Select order
Dim view As DataView = query.AsDataView()
bindingSource1.DataSource = view
注釈
の主な機能DataViewは、Windows フォームとWeb Formsの両方でデータ バインディングを許可することです。
さらに、a を DataView カスタマイズして、データの DataTableサブセットを表示することもできます。 この機能を使用すると、同じ DataTableコントロールにバインドされた 2 つのコントロールを使用できますが、異なるバージョンのデータが表示されます。 たとえば、1 つのコントロールがテーブル内のすべての行を表示するコントロールに DataView バインドされ、2 つ目のコントロールは削除 DataTableされた行のみを表示するように構成できます。 プロパティ DataTable もあります DefaultView 。 これにより、テーブルの既定値 DataView が返されます。 たとえば、テーブルにカスタム ビューを作成する場合は、 RowFilter DataView DefaultView.
フィルター処理された並べ替えられたデータ ビューを作成するには、プロパティとSortプロパティを設定しますRowFilter。 次に、プロパティを Item[] 使用して 1 つ DataRowViewを返します。
およびメソッドを使用して AddNew 、一連の行を追加および Delete 削除することもできます。 これらのメソッドを使用する場合、プロパティは RowStateFilter 、削除された行または新しい行のみを表示 DataViewするように設定できます。
注意
の並べ替え基準DataView
を明示的に指定しない場合、DataRowView``DataView
オブジェクトは、.DataRow
DataTable.Rows
DataRowCollection
LINQ to DataSetを使用すると、開発者は LINQ を使用して複雑で強力なクエリをDataSet作成できます。 ただし、LINQ to DataSet クエリはオブジェクトのDataRow列挙体を返しますが、バインド シナリオでは簡単には使用できません。 DataViewは、LINQ to DataSet クエリから作成でき、そのクエリのフィルター処理と並べ替えの特性を受け取ります。 LINQ to DataSet を使うと、文字列ベースのフィルター処理や並べ替え処理よりはるかに複雑で強力な LINQ 式ベースのフィルター処理と並べ替え処理が提供されて、DataView の機能が拡張されます。 詳細については、「データ バインディングとLINQ to DataSet」を参照してください。
コンストラクター
DataView() |
DataView クラスの新しいインスタンスを初期化します。 |
DataView(DataTable) | |
DataView(DataTable, String, String, DataViewRowState) |
指定された DataTable、RowFilter、Sort、および DataViewRowState を使用して、DataView クラスの新しいインスタンスを初期化します。 |
プロパティ
AllowDelete |
削除が許可されているかどうかを示す値を取得または設定します。 |
AllowEdit |
更新が許可されるかどうかを示す値を取得または設定します。 |
AllowNew |
AddNew() メソッドを使用して新しい行を追加できるかどうかを示す値を取得または設定します。 |
ApplyDefaultSort |
既定の並べ替えを使用するかどうかを示す値を取得または設定します。 既定の並べ替えは、PrimaryKey で指定されているとおり、すべての主キーで "昇順" です。 |
Container |
コンポーネントを格納するコンテナーを取得します。 (継承元 MarshalByValueComponent) |
Count |
RowFilter と RowStateFilter が適用された後に、DataView 内のレコード数を取得します。 |
DataViewManager |
このビューに関連付けられている DataViewManager を取得します。 |
DesignMode |
コンポーネントが現在デザイン モードかどうかを示す値を取得します。 (継承元 MarshalByValueComponent) |
Events |
コンポーネントに結び付けられているイベント ハンドラーのリストを取得します。 (継承元 MarshalByValueComponent) |
IsInitialized |
コンポーネントが初期化されているかどうかを示す値を取得します。 |
IsOpen |
データ ソースが現在開かれており、かつ DataTable 上のデータのビューを投射しているのかどうかを示す値を取得します。 |
Item[Int32] |
指定したテーブルからデータの行を取得します。 |
RowFilter |
DataView の中で表示する行のフィルター処理に使用する式を取得または設定します。 |
RowStateFilter |
DataView で使用される行の状態のフィルターを取得または設定します。 |
Site |
コンポーネントのサイトを取得します。値の設定も可能です。 (継承元 MarshalByValueComponent) |
Sort |
1 つ以上の並べ替え列、および DataView の並べ替え順序を取得または設定します。 |
Table |
ソース DataTable を取得または設定します。 |
メソッド
events
Disposed |
コンポーネントの Disposed イベントを待機するイベント ハンドラーを追加します。 (継承元 MarshalByValueComponent) |
Initialized |
DataView の初期化が完了した時点で発生します。 |
ListChanged |
DataView によって管理されているリストが変更されたときに発生します。 |
明示的なインターフェイスの実装
拡張メソッド
Cast<TResult>(IEnumerable) |
IEnumerable の要素を、指定した型にキャストします。 |
OfType<TResult>(IEnumerable) |
指定された型に基づいて IEnumerable の要素をフィルター処理します。 |
AsParallel(IEnumerable) |
クエリの並列化を有効にします。 |
AsQueryable(IEnumerable) |
IEnumerable を IQueryable に変換します。 |
適用対象
スレッド セーフ
この型は、マルチスレッド読み取り操作でも安全です。 すべての書き込み操作を同期する必要があります。