BindingSource.Sort プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

列名の後に "ASC" (昇順) または "DESC" (降順) を付けた、大文字と小文字が区別される文字列。既定値は null 参照 (Visual Basic では Nothing) です。

Sort プロパティは、行の並べ替えに使用する列名と並べ替えの順序を指定する、大文字と小文字が区別される文字列です。既定では、列は昇順に並べ替えられます。複数の列を指定する場合は、"State, ZipCode DESC" のようにコンマで区切ります。
基底のリストが並べ替えをサポートするには、IBindingList インターフェイスまたは IBindingListView インターフェイスを実装している必要があります。この機能がサポートされているかどうかは、SupportsSorting プロパティを使用して問い合わせることができます。SupportsAdvancedSorting プロパティが true の場合は、複数列の並べ替えがサポートされています。
Sort プロパティを設定すると、内部リストが型に応じて次のように変更されます。
-
リストが IBindingList 型である場合、内部リストの IBindingList.SortProperty プロパティと IBindingList.SortDirection プロパティが設定されます。
-
リストが IBindingListView 型である場合、IBindingListView.SortDescriptions プロパティが設定されます。
内部リストの並べ替えプロパティが変更されるのは、並べ替え文字列が null 参照 (Visual Basic では Nothing) でない場合のみです。このプロパティの get アクセサは、内部リストの並べ替え値を取得せず、代わりに set アクセサの値を返します。Sort プロパティの値は、データ ソースが変更されても保持されます。

Filter プロパティと Sort プロパティのコード例を次に示します。この例を実行するには、BindingSource1 という名前の BindingSource と、dataGridView1 という名前の DataGridView を含むフォームにコードを貼り付けます。次に、フォームの読み込みイベントを処理し、読み込みイベント処理メソッドで InitializeSortedFilteredBindingSource を呼び出します。Visual Basic を使用する場合、System.Data.dll への参照を追加する必要があります。
Private Sub InitializeSortedFilteredBindingSource() ' Create the connection string, data adapter and data table. Dim connectionString As New SqlConnection("Initial Catalog=Northwind;" & _ "Data Source=localhost;Integrated Security=SSPI;") Dim customersTableAdapter As New SqlDataAdapter("Select * from Customers", _ connectionString) Dim customerTable As New DataTable() ' Fill the the adapter with the contents of the customer table. customersTableAdapter.Fill(customerTable) ' Set data source for BindingSource1. BindingSource1.DataSource = customerTable ' Filter the items to show contacts who are owners. BindingSource1.Filter = "ContactTitle='Owner'" ' Sort the items on the company name in descending order. BindingSource1.Sort = "Country DESC, Address ASC" ' Set the data source for dataGridView1 to BindingSource1. dataGridView1.DataSource = BindingSource1 End Sub
private void InitializeSortedFilteredBindingSource() { // Create the connection string, data adapter and data table. SqlConnection connectionString = new SqlConnection("Initial Catalog=Northwind;" + "Data Source=localhost;Integrated Security=SSPI;"); SqlDataAdapter customersTableAdapter = new SqlDataAdapter("Select * from Customers", connectionString); DataTable customerTable = new DataTable(); // Fill the the adapter with the contents of the customer table. customersTableAdapter.Fill(customerTable); // Set data source for BindingSource1. BindingSource1.DataSource = customerTable; // Filter the items to show contacts who are owners. BindingSource1.Filter = "ContactTitle='Owner'"; // Sort the items on the company name in descending order. BindingSource1.Sort = "Country DESC, Address ASC"; // Set the data source for dataGridView1 to BindingSource1. dataGridView1.DataSource = BindingSource1; }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBindingSource.Sort プロパティを検索する場合は、下記のリンクをクリックしてください。

- BindingSource.Sort プロパティのページへのリンク