DataView クラス

定義

並べ替え、フィルター処理、検索、編集、およびナビゲーションを実行するための、データ連結可能な、カスタマイズされた DataTable のビューを表します。 DataView はデータを格納しませんが、代わりに対応する DataTable の接続したビューを表します。 DataView のデータに対して加えた変更は、DataTable に影響します。 DataTable のデータに対して加えた変更は、それに関連付けられているすべての DataView に影響します。

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
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 行の 1 つ 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.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(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の両方でデータ バインディングを許可することです。

さらに、 から DataView データ DataTableのサブセットを表示するように をカスタマイズすることもできます。 この機能を使用すると、2 つのコントロールを同じ DataTableにバインドできますが、異なるバージョンのデータを表示できます。 たとえば、1 つのコントロールが テーブル内のすべての行を表示する にバインド DataView され、2 つ目の コントロールが から DataTable削除された行のみを表示するように構成される場合があります。 DataTableには DefaultView プロパティもあります。 これにより、テーブルの既定値 DataView が返されます。 たとえば、テーブルにカスタム ビューを作成する場合は、 によって返される に DataViewDefaultView設定RowFilterします。

フィルター処理された並べ替えられたデータ ビューを作成するには、 プロパティと Sort プロパティをRowFilter設定します。 次に、 プロパティを Item[] 使用して 1 つの DataRowViewを返します。

メソッドと メソッドを使用して、行のセットに対する AddNew 追加と Delete 削除を行うこともできます。 これらのメソッドを使用する場合、 プロパティを RowStateFilter 設定して、 によって DataView削除された行または新しい行のみを表示するように指定できます。

Note

の並べ替え基準DataViewDataRowViewを明示的に指定しない場合、 の DataView オブジェクトは、 内の DataView の対応するDataRowインデックスにDataTable.RowsDataRowCollection基づいて並べ替えられます。

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 クラスの新しいインスタンスを初期化します。

DataView(DataTable, String, String, DataViewRowState)

指定された DataTableRowFilterSort、および DataViewRowState を使用して、DataView クラスの新しいインスタンスを初期化します。

プロパティ

AllowDelete

削除が許可されているかどうかを示す値を取得または設定します。

AllowEdit

更新が許可されるかどうかを示す値を取得または設定します。

AllowNew

AddNew() メソッドを使用して新しい行を追加できるかどうかを示す値を取得または設定します。

ApplyDefaultSort

既定の並べ替えを使用するかどうかを示す値を取得または設定します。 既定の並べ替えは、PrimaryKey で指定されているとおり、すべての主キーで "昇順" です。

Container

コンポーネントを格納するコンテナーを取得します。

(継承元 MarshalByValueComponent)
Count

RowFilterRowStateFilter が適用された後に、DataView 内のレコード数を取得します。

DataViewManager

このビューに関連付けられている DataViewManager を取得します。

DesignMode

コンポーネントが現在デザイン モードかどうかを示す値を取得します。

(継承元 MarshalByValueComponent)
Events

コンポーネントに結び付けられているイベント ハンドラーのリストを取得します。

(継承元 MarshalByValueComponent)
IsInitialized

コンポーネントが初期化されているかどうかを示す値を取得します。

IsOpen

データ ソースが現在開かれており、かつ DataTable 上のデータのビューを投射しているのかどうかを示す値を取得します。

Item[Int32]

指定したテーブルからデータの行を取得します。

RowFilter

DataView の中で表示する行のフィルター処理に使用する式を取得または設定します。

RowStateFilter

DataView で使用される行の状態のフィルターを取得または設定します。

Site

コンポーネントのサイトを取得します。値の設定も可能です。

(継承元 MarshalByValueComponent)
Sort

1 つ以上の並べ替え列、および DataView の並べ替え順序を取得または設定します。

Table

ソース DataTable を取得または設定します。

メソッド

AddNew()

DataView に新しい行を追加します。

BeginInit()

フォームまたは別のコンポーネントで使用する DataView の初期化を開始します。 初期化は実行時に発生します。

Close()

DataView を閉じます。

ColumnCollectionChanged(Object, CollectionChangeEventArgs)

DataColumnCollection が正常に変更された後に発生します。

CopyTo(Array, Int32)

配列に項目をコピーします。 Web フォームのインターフェイスに対してのみ。

Delete(Int32)

指定したインデックスの行を削除します。

Dispose()

MarshalByValueComponent によって使用されているすべてのリソースを解放します。

(継承元 MarshalByValueComponent)
Dispose(Boolean)

DataView オブジェクトによって使用されていたリソース (メモリを除く) を破棄します。

EndInit()

フォームまたは別のコンポーネントで使用する DataView の初期化を終了します。 初期化は実行時に発生します。

Equals(DataView)

指定された DataView インスタンスが等しいかどうかを判断します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
Find(Object)

指定された並べ替えキーの値で DataView 内の行を検索します。

Find(Object[])

指定された並べ替えキーの値で DataView 内の行を検索します。

FindRows(Object)

列が指定した並べ替えキーの値と一致する DataRowView オブジェクトの配列を返します。

FindRows(Object[])

列が指定した並べ替えキーの値と一致する DataRowView オブジェクトの配列を返します。

GetEnumerator()

この DataView の列挙子を取得します

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetService(Type)

IServiceProvider を実装しているオブジェクトを取得します。

(継承元 MarshalByValueComponent)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IndexListChanged(Object, ListChangedEventArgs)

DataView が正常に変更された後に発生します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
OnListChanged(ListChangedEventArgs)

ListChanged イベントを発生させます。

Open()

DataView を開きます。

Reset()

内部使用専用に予約されています。

ToString()

Component の名前 (存在する場合) を格納する String を返します。 このメソッドはオーバーライドできません。

(継承元 MarshalByValueComponent)
ToTable()

既存のDataView の行に基づく新しい DataTable を作成して返します。

ToTable(Boolean, String[])

既存のDataView の行に基づく新しい DataTable を作成して返します。

ToTable(String)

既存のDataView の行に基づく新しい DataTable を作成して返します。

ToTable(String, Boolean, String[])

既存のDataView の行に基づく新しい DataTable を作成して返します。

UpdateIndex()

内部使用専用に予約されています。

UpdateIndex(Boolean)

内部使用専用に予約されています。

イベント

Disposed

コンポーネントの Disposed イベントを待機するイベント ハンドラーを追加します。

(継承元 MarshalByValueComponent)
Initialized

DataView の初期化が完了した時点で発生します。

ListChanged

DataView によって管理されているリストが変更されたときに発生します。

明示的なインターフェイスの実装

IBindingList.AddIndex(PropertyDescriptor)

このメンバーの詳細については、「AddIndex(PropertyDescriptor)」をご覧ください。

IBindingList.AddNew()

このメンバーの詳細については、「AddNew()」をご覧ください。

IBindingList.AllowEdit

このメンバーの詳細については、「AllowEdit」をご覧ください。

IBindingList.AllowNew

このメンバーの詳細については、「AllowNew」をご覧ください。

IBindingList.AllowRemove

このメンバーの詳細については、「AllowRemove」をご覧ください。

IBindingList.ApplySort(PropertyDescriptor, ListSortDirection)

このメンバーの詳細については、「ApplySort(PropertyDescriptor, ListSortDirection)」をご覧ください。

IBindingList.Find(PropertyDescriptor, Object)

このメンバーの詳細については、「Find(PropertyDescriptor, Object)」をご覧ください。

IBindingList.IsSorted

このメンバーの詳細については、「IsSorted」をご覧ください。

IBindingList.RemoveIndex(PropertyDescriptor)

このメンバーの詳細については、「RemoveIndex(PropertyDescriptor)」をご覧ください。

IBindingList.RemoveSort()

このメンバーの詳細については、「RemoveSort()」をご覧ください。

IBindingList.SortDirection

このメンバーの詳細については、「SortDirection」をご覧ください。

IBindingList.SortProperty

このメンバーの詳細については、「SortProperty」をご覧ください。

IBindingList.SupportsChangeNotification

このメンバーの詳細については、「SupportsChangeNotification」をご覧ください。

IBindingList.SupportsSearching

このメンバーの詳細については、「SupportsSearching」をご覧ください。

IBindingList.SupportsSorting

このメンバーの詳細については、「SupportsSorting」をご覧ください。

IBindingListView.ApplySort(ListSortDescriptionCollection)

このメンバーの詳細については、「ApplySort(ListSortDescriptionCollection)」をご覧ください。

IBindingListView.Filter

このメンバーの詳細については、「Filter」をご覧ください。

IBindingListView.RemoveFilter()

このメンバーの詳細については、「RemoveFilter()」をご覧ください。

IBindingListView.SortDescriptions

このメンバーの詳細については、「SortDescriptions」をご覧ください。

IBindingListView.SupportsAdvancedSorting

このメンバーの詳細については、「SupportsAdvancedSorting」をご覧ください。

IBindingListView.SupportsFiltering

このメンバーの詳細については、「SupportsFiltering」をご覧ください。

ICollection.IsSynchronized

このメンバーの詳細については、「IsSynchronized」をご覧ください。

ICollection.SyncRoot

このメンバーの詳細については、「SyncRoot」をご覧ください。

IList.Add(Object)

このメンバーの詳細については、「Add(Object)」をご覧ください。

IList.Clear()

このメンバーの詳細については、「Clear()」をご覧ください。

IList.Contains(Object)

このメンバーの詳細については、「Contains(Object)」をご覧ください。

IList.IndexOf(Object)

このメンバーの詳細については、「IndexOf(Object)」をご覧ください。

IList.Insert(Int32, Object)

このメンバーの詳細については、「Insert(Int32, Object)」をご覧ください。

IList.IsFixedSize

このメンバーの詳細については、「IsFixedSize」をご覧ください。

IList.IsReadOnly

このメンバーの詳細については、「IsReadOnly」をご覧ください。

IList.Item[Int32]

このメンバーの詳細については、「Item[Int32]」をご覧ください。

IList.Remove(Object)

このメンバーの詳細については、「Remove(Object)」をご覧ください。

IList.RemoveAt(Int32)

このメンバーの詳細については、「RemoveAt(Int32)」をご覧ください。

ITypedList.GetItemProperties(PropertyDescriptor[])

このメンバーの詳細については、「GetItemProperties(PropertyDescriptor[])」をご覧ください。

ITypedList.GetListName(PropertyDescriptor[])

このメンバーの詳細については、「GetListName(PropertyDescriptor[])」をご覧ください。

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

スレッド セーフ

この型は、マルチスレッド読み取り操作に対して安全です。 すべての書き込み操作を同期する必要があります。

こちらもご覧ください