DataView.Sort 속성

정의

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 해당 DataRowDataTable.RowsDataRowCollection인덱스 에 따라 정렬됩니다.

자세한 내용은 DataView를 참조하세요.

적용 대상

추가 정보