次の方法で共有


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

次の例では、LINQ to DataSet クエリによって合計順に並べ替えられたオンライン注文の 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 の主な機能は、Windows フォームと Web フォームの両方でデータ バインディングを許可することです。

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

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

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

手記

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

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)

指定した DataTableを使用して、DataView クラスの新しいインスタンスを初期化します。

DataView(DataTable, String, String, DataViewRowState)

指定した DataTableRowFilterSort、および 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

DataViewの並べ替え列または並べ替え順序を取得または設定します。

Table

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

メソッド

AddNew()

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

BeginInit()

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

Close()

DataViewを閉じます。

ColumnCollectionChanged(Object, CollectionChangeEventArgs)

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

CopyTo(Array, Int32)

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

Delete(Int32)

指定したインデックス位置にある行を削除します。

Dispose()

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

(継承元 MarshalByValueComponent)
Dispose(Boolean)

DataView オブジェクトによって使用される (メモリ以外の) リソースを破棄します。

EndInit()

フォームで使用される DataView または別のコンポーネントによって使用される 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[])を参照してください。

拡張メソッド

GetKeyedService<T>(IServiceProvider, Object)

IServiceProviderから T 型のサービスを取得します。

GetKeyedServices(IServiceProvider, Type, Object)

IServiceProviderから serviceType 型のサービスの列挙体を取得します。

GetKeyedServices<T>(IServiceProvider, Object)

IServiceProviderから T 型のサービスの列挙体を取得します。

GetRequiredKeyedService(IServiceProvider, Type, Object)

IServiceProviderから serviceType 型のサービスを取得します。

GetRequiredKeyedService<T>(IServiceProvider, Object)

IServiceProviderから T 型のサービスを取得します。

CreateAsyncScope(IServiceProvider)

スコープ付きサービスの解決に使用できる新しい AsyncServiceScope を作成します。

CreateScope(IServiceProvider)

スコープ付きサービスの解決に使用できる新しい IServiceScope を作成します。

GetRequiredService(IServiceProvider, Type)

IServiceProviderから serviceType 型のサービスを取得します。

GetRequiredService<T>(IServiceProvider)

IServiceProviderから T 型のサービスを取得します。

GetService<T>(IServiceProvider)

IServiceProviderから T 型のサービスを取得します。

GetServices(IServiceProvider, Type)

IServiceProviderから serviceType 型のサービスの列挙体を取得します。

GetServices<T>(IServiceProvider)

IServiceProviderから T 型のサービスの列挙体を取得します。

GetFakeLogCollector(IServiceProvider)

偽のロガーに送信されたログ レコードを収集するオブジェクトを取得します。

GetFakeRedactionCollector(IServiceProvider)

依存関係挿入コンテナーから偽の redactor コレクター インスタンスを取得します。

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryableに変換します。

適用対象

スレッド セーフ

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

こちらもご覧ください