DataView.Sort 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
열 또는 열 정렬을 가져오거나 설정하고 DataView정렬 순서를 설정합니다.
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"(내림차순)가 포함된 문자열입니다. 열은 기본적으로 오름차순으로 정렬됩니다. 여러 열을 쉼표로 구분할 수 있습니다.
- 특성
예제
다음 예제에서는 테이블을 두 개의 열로 정렬하도록 DataView 지시합니다.
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
대한 정렬 조건을 명시적으로 지정하지 않으면 DataView
DataRowView
개체는 DataTable.Rows
DataRowCollection
해당 DataRow
인덱스 기준으로 정렬됩니다.
자세한 내용은 DataViews참조하세요.