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
정렬 조건을 명시적으로 지정하지 않으면 의 DataRowView
개체는 의 DataView
해당 DataRow
DataTable.Rows
DataRowCollection
인덱스 에 따라 정렬됩니다.
자세한 내용은 DataView를 참조하세요.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기