DataTableExtensions.AsDataView メソッド

定義

オーバーロード

AsDataView(DataTable)

LINQ 対応の DataView オブジェクトを作成して返します。

AsDataView<T>(EnumerableRowCollection<T>)

LINQ to DataSet クエリを表す LINQ 対応DataViewオブジェクトを作成して返します。

AsDataView(DataTable)

LINQ 対応の DataView オブジェクトを作成して返します。

public:
[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::DataTable ^ table);
public static System.Data.DataView AsDataView (this System.Data.DataTable table);
static member AsDataView : System.Data.DataTable -> System.Data.DataView
<Extension()>
Public Function AsDataView (table As DataTable) As DataView

パラメーター

table
DataTable

LINQ 対応の DataTable を作成する元となる DataView

戻り値

LINQ 対応の DataView オブジェクト。

次の例では、SalesOrderDetail テーブルから をDataView作成し、コントロールのプロキシDataGridViewとして機能する オブジェクトのBindingSourceデータ ソースとして設定します。

DataTable orders = dataSet.Tables["SalesOrderDetail"];

DataView view = orders.AsDataView();
bindingSource1.DataSource = view;

dataGridView1.AutoResizeColumns();
Dim orders As DataTable = dataSet.Tables("SalesOrderDetail")

Dim view As DataView = orders.AsDataView()
bindingSource1.DataSource = view
dataGridView1.AutoResizeColumns()

注釈

DataViewを使用すると、LINQ to DataSetのデータ バインディング シナリオが可能になり、型指定または型DataTable指定されていない から作成でき、そのテーブルの既定のビューが提供されます。 DataView から DataTable を作成した後、フィルターおよび並べ替えを設定できます。 DataView次に、 や DataGridViewなどの DataGrid UI コントロールにバインドされ、単純なデータ バインディング モデルが提供されます。

詳細と例については、「 DataView オブジェクトの作成」を参照してください。

適用対象

AsDataView<T>(EnumerableRowCollection<T>)

LINQ to DataSet クエリを表す LINQ 対応DataViewオブジェクトを作成して返します。

public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::EnumerableRowCollection<T> ^ source);
public static System.Data.DataView AsDataView<T> (this System.Data.EnumerableRowCollection<T> source) where T : System.Data.DataRow;
static member AsDataView : System.Data.EnumerableRowCollection<'T (requires 'T :> System.Data.DataRow)> -> System.Data.DataView (requires 'T :> System.Data.DataRow)
<Extension()>
Public Function AsDataView(Of T As DataRow) (source As EnumerableRowCollection(Of T)) As DataView

型パラメーター

T

ソース シーケンスのオブジェクトの型 (通常は DataRow)。

パラメーター

source
EnumerableRowCollection<T>

LINQ 対応DataViewLINQ to DataSet作成元のクエリのソース。

戻り値

LINQ 対応の DataView オブジェクト。

次の例では、合計期限で並べ替えられたオンライン注文の を DataView 作成します。

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を使用すると、LINQ to DataSetのデータ バインディング シナリオが可能になり、LINQ to DataSet クエリから作成できます。 は DataView クエリ自体を表し、クエリ上のビューではありません。 新しく作成 DataView された は、作成元のクエリからのフィルター処理と並べ替えの情報を推論します。 DataView次に、 や DataGridViewなどの DataGrid UI コントロールにバインドされ、単純なデータ バインディング モデルが提供されます。

入力パラメーターのパラメーター Tsource には、 型 DataRow または から DataRow派生した型のみを指定できます。

次のクエリ演算子は、 の作成 DataViewに使用されるクエリでのみサポートされています。

詳細と例については、「 DataView オブジェクトの作成」を参照してください。

適用対象