BindingSource.Sort 속성

정의

정렬에 사용되는 열 이름과 데이터 소스의 행을 표시하기 위한 정렬 순서를 가져오거나 설정합니다.

public:
 property System::String ^ Sort { System::String ^ get(); void set(System::String ^ value); };
public string Sort { get; set; }
public string? Sort { get; set; }
member this.Sort : string with get, set
Public Property Sort As String

속성 값

열 이름과 "ASC"(오름차순) 또는 "DESC"(내림차순)로 구성된 문자열로, 대/소문자를 구분합니다. 기본값은 null입니다.

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다 합니다 Sort 사용 하 여 기본 정렬을 수행 하는 속성을 DataView입니다. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 PopulateDataViewAndSort 폼의 생성자에서 또는 Load 이벤트 처리 메서드. 폼을 가져와야 합니다 System.XmlSystem.IO 네임 스페이스입니다.

private void PopulateDataViewAndSort()
{
    DataSet set1 = new DataSet();

    // Some xml data to populate the DataSet with.
    string musicXml =
        "<?xml version='1.0' encoding='UTF-8'?>" +
        "<music>" +
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" +
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
        "</music>";

    // Read the xml.
    StringReader reader = new StringReader(musicXml);
    set1.ReadXml(reader);

    // Get a DataView of the table contained in the dataset.
    DataTableCollection tables = set1.Tables;
    DataView view1 = new DataView(tables[0]);

    // Create a DataGridView control and add it to the form.
    DataGridView datagridview1 = new DataGridView();
    datagridview1.AutoGenerateColumns = true;
    this.Controls.Add(datagridview1);

    // Create a BindingSource and set its DataSource property to
    // the DataView.
    BindingSource source1 = new BindingSource();
    source1.DataSource = view1;

    // Set the data source for the DataGridView.
    datagridview1.DataSource = source1;

    source1.Sort = "cd";
}
Private Sub PopulateDataViewAndSort() 
    Dim set1 As New DataSet()
    
    ' Some xml data to populate the DataSet with.
    Dim musicXml As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
        "<music>" & _
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" & _
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" & _
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" & _
         "</music>"
    
    ' Read the xml.
    Dim reader As New StringReader(musicXml)
    set1.ReadXml(reader)
    
    ' Get a DataView of the table contained in the dataset.
    Dim tables As DataTableCollection = set1.Tables
    Dim view1 As New DataView(tables(0))
    
    ' Create a DataGridView control and add it to the form.
    Dim datagridview1 As New DataGridView()
    datagridview1.AutoGenerateColumns = True
    Me.Controls.Add(datagridview1)
    
    ' Create a BindingSource and set its DataSource property to
    ' the DataView.
    Dim source1 As New BindingSource()
    source1.DataSource = view1
    
    ' Set the data source for the DataGridView.
    datagridview1.DataSource = source1
    
    source1.Sort = "cd"

End Sub

다음 예제에서는 사용 하는 방법을 보여 줍니다 합니다 Sort 속성을 사용 하 여 정렬 고급는 DataView합니다. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 PopulateDataViewAndAdvancedSort 폼의 생성자에서 또는 Load 이벤트 처리 메서드. 폼을 가져와야 합니다 System.XmlSystem.IO 네임 스페이스입니다.

private void PopulateDataViewAndAdvancedSort()
{
    DataSet set1 = new DataSet();

    // Some xml data to populate the DataSet with.
    string musicXml =
        "<?xml version='1.0' encoding='UTF-8'?>" +
        "<music>" +
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" +
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" +
        "<recording><artist>U2</artist><cd>Joshua Tree</cd></recording>" +
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
        "</music>";

    // Read the xml.
    StringReader reader = new StringReader(musicXml);
    set1.ReadXml(reader);

    // Get a DataView of the table contained in the dataset.
    DataTableCollection tables = set1.Tables;
    DataView view1 = new DataView(tables[0]);

    // Create a DataGridView control and add it to the form.
    DataGridView datagridview1 = new DataGridView();
    datagridview1.AutoGenerateColumns = true;
    this.Controls.Add(datagridview1);

    // Create a BindingSource and set its DataSource property to
    // the DataView.
    BindingSource source1 = new BindingSource();
    source1.DataSource = view1;

    // Set the data source for the DataGridView.
    datagridview1.DataSource = source1;

    source1.Sort = "artist ASC, cd ASC";
}
Private Sub PopulateDataViewAndAdvancedSort() 
    Dim set1 As New DataSet()
    
    ' Some xml data to populate the DataSet with.
    Dim musicXml As String = "<?xml version='1.0' encoding='UTF-8'?>" & _
        "<music>" & _
        "<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" & _
        "<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" & _
        "<recording><artist>Dave Matthews</artist><cd>Live at Red Rocks</cd></recording>" & _
        "<recording><artist>U2</artist><cd>Joshua Tree</cd></recording>" & _
        "<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" & _
        "<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" & _
        "</music>"
    
    ' Read the xml.
    Dim reader As New StringReader(musicXml)
    set1.ReadXml(reader)
    
    ' Get a DataView of the table contained in the dataset.
    Dim tables As DataTableCollection = set1.Tables
    Dim view1 As New DataView(tables(0))
    
    ' Create a DataGridView control and add it to the form.
    Dim datagridview1 As New DataGridView()
    datagridview1.AutoGenerateColumns = True
    Me.Controls.Add(datagridview1)
    
    ' Create a BindingSource and set its DataSource property to
    ' the DataView.
    Dim source1 As New BindingSource()
    source1.DataSource = view1
    
    ' Set the data source for the DataGridView.
    datagridview1.DataSource = source1
    
    source1.Sort = "artist ASC, cd ASC"

설명

Sort 속성은 정렬 방향 함께 행을 정렬 하는 데 열 이름을 지정 하는 대/소문자 구분 문자열입니다. 열은 기본적으로 오름차순으로 정렬됩니다. 여러 열 수 있습니다 수 쉼표로 구분 하 여 같은 "State, ZipCode DESC"합니다.

기본 목록이 정렬을 지원 하려면 구현 해야 합니다 IBindingList 또는 IBindingListView 인터페이스입니다. 이 기능을 통해 쿼리할 수 있습니다는 SupportsSorting 속성입니다. 여러 열 정렬을 사용할 수는 SupportsAdvancedSorting 속성은 true합니다.

설정 된 Sort 속성이 해당 유형에 따라 내부 목록에 변경 됩니다.

정렬 문자열이 없는 경우 내부 목록의 정렬 속성만 변경 됩니다 null합니다. 합니다 get 이 속성에 대 한 접근자는 내부 목록의 정렬 값을 검색 하지 것입니다; 대신 반환 됩니다는 set 접근자 값입니다. 값을 Sort 속성 데이터 소스가 변경 되어도 유지 됩니다.

적용 대상

추가 정보