BindingSource.Sort 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
정렬에 사용되는 열 이름과 데이터 원본의 행을 보기 위한 정렬 순서를 가져오거나 설정합니다.
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에 붙여넣고 양식의 생성자 또는 Load 이벤트 처리 메서드에서 호출 PopulateDataViewAndSort 합니다. 양식에서 네임스페이스와 네임스페이 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에 붙여넣고 양식의 생성자 또는 Load 이벤트 처리 메서드에서 호출 PopulateDataViewAndAdvancedSort 합니다. 양식에서 네임스페이스와 네임스페이 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"구분할 수 있습니다.
정렬을 지원하려면 기본 목록이 또는 IBindingListView 인터페이스를 IBindingList 구현해야 합니다. 이 기능은 속성을 통해 SupportsSorting 쿼리할 수 있습니다. 속성true이 .인 경우 여러 열 정렬을 SupportsAdvancedSorting 사용할 수 있습니다.
Sort 속성을 설정하면 해당 형식에 따라 내부 목록이 변경됩니다.
목록이 형식 IBindingListIBindingList.SortProperty 이면 내부 목록에서 속성과 IBindingList.SortDirection 속성이 설정됩니다.
목록이 형식 IBindingListView이면 속성이 IBindingListView.SortDescriptions 설정됩니다.
내부 목록의 정렬 속성은 정렬 문자열이 아닌 null경우에만 변경됩니다.
get 이 속성의 접근자는 내부 목록의 정렬 값을 검색하지 않고 대신 접근자 set 값을 반환합니다. 속성 값은 데이터 원본이 Sort 변경될 때 유지됩니다.