DataView.Sort プロパティ
定義
public:
property System::String ^ Sort { System::String ^ get(); void set(System::String ^ value); };
public string Sort { get; set; }
[System.Data.DataSysDescription("DataViewSortDescr")]
public string Sort { get; set; }
member this.Sort : string with get, set
[<System.Data.DataSysDescription("DataViewSortDescr")>]
member this.Sort : string with get, set
Public Property Sort As String
プロパティ値
列名の後に "ASC" (昇順) または "DESC" (降順) を含む文字列。A string that contains the column name followed by "ASC" (ascending) or "DESC" (descending). 既定では列は昇順で並べ替えられます。Columns are sorted ascending by default. 複数の列をコンマで区切ることができます。Multiple columns can be separated by commas.
- 属性
例
次の例では、 DataView テーブルを2つの列で並べ替えるようにに指示します。The following example instructs the DataView to sort the table by two columns.
using System.Data;
using System;
public class A {
static void Main(string[] args) {
DataTable locationTable = new DataTable("Location");
// Add two columns
locationTable.Columns.Add("State");
locationTable.Columns.Add("ZipCode");
// Add data
locationTable.Rows.Add("Washington", "98052");
locationTable.Rows.Add("California", "90001");
locationTable.Rows.Add("Hawaii", "96807");
locationTable.Rows.Add("Hawaii", "96801");
locationTable.AcceptChanges();
Console.WriteLine("Rows in original order\n State \t\t ZipCode");
foreach (DataRow row in locationTable.Rows) {
Console.WriteLine(" {0} \t {1}", row["State"], row["ZipCode"]);
}
// Create DataView
DataView view = new DataView(locationTable);
// Sort by State and ZipCode column in descending order
view.Sort = "State ASC, ZipCode ASC";
Console.WriteLine("\nRows in sorted order\n State \t\t ZipCode");
foreach (DataRowView row in view) {
Console.WriteLine(" {0} \t {1}", row["State"], row["ZipCode"]);
}
}
}
Imports System.Data
Public Class A
Public Shared Sub Main(args As String())
Dim locationTable As New DataTable("Location")
' Add two columns
locationTable.Columns.Add("State")
locationTable.Columns.Add("ZipCode")
' Add data
locationTable.Rows.Add("Washington", "98052")
locationTable.Rows.Add("California", "90001")
locationTable.Rows.Add("Hawaii", "96807")
locationTable.Rows.Add("Hawaii", "96801")
locationTable.AcceptChanges()
Console.WriteLine("Rows in original order" & vbLf & " State " & vbTab & vbTab & " ZipCode")
For Each row As DataRow In locationTable.Rows
Console.WriteLine(" {0} " & vbTab & " {1}", row("State"), row("ZipCode"))
Next
' Create DataView
Dim view As New DataView(locationTable)
' Sort by State and ZipCode column in descending order
view.Sort = "State ASC, ZipCode ASC"
Console.WriteLine(vbLf & "Rows in sorted order" & vbLf & " State " & vbTab & vbTab & " ZipCode")
For Each row As DataRowView In view
Console.WriteLine(" {0} " & vbTab & " {1}", row("State"), row("ZipCode"))
Next
End Sub
End Class
注釈
の並べ替え条件を明示的に指定しない場合、 DataView
DataRowView
内のオブジェクトは DataView
、内の対応するのインデックスに基づいて並べ替えられ DataRow
DataTable.Rows
DataRowCollection
ます。If you do not explicitly specify sort criteria for DataView
, the DataRowView
objects in DataView
are sorted based on the index of its corresponding DataRow
in the DataTable.Rows
DataRowCollection
.
詳しくは、「DataView」をご覧ください。For more information, see DataViews.