DataGridView.SortCompare 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DataGridView가 정렬 작업을 수행하기 위해 두 셀 값을 비교할 때 발생합니다.
public:
event System::Windows::Forms::DataGridViewSortCompareEventHandler ^ SortCompare;
public event System.Windows.Forms.DataGridViewSortCompareEventHandler SortCompare;
public event System.Windows.Forms.DataGridViewSortCompareEventHandler? SortCompare;
member this.SortCompare : System.Windows.Forms.DataGridViewSortCompareEventHandler
Public Custom Event SortCompare As DataGridViewSortCompareEventHandler
이벤트 유형
예제
다음 코드 예제를 사용 SortCompare 하는 방법에 설명 합니다 여러 열 정렬에서 합니다. 이 예제는 방법: Windows Forms DataGridView 컨트롤에서 정렬 사용자 지정합니다.
private void dataGridView1_SortCompare(object sender,
DataGridViewSortCompareEventArgs e)
{
// Try to sort based on the cells in the current column.
e.SortResult = System.String.Compare(
e.CellValue1.ToString(), e.CellValue2.ToString());
// If the cells are equal, sort based on the ID column.
if (e.SortResult == 0 && e.Column.Name != "ID")
{
e.SortResult = System.String.Compare(
dataGridView1.Rows[e.RowIndex1].Cells["ID"].Value.ToString(),
dataGridView1.Rows[e.RowIndex2].Cells["ID"].Value.ToString());
}
e.Handled = true;
}
Private Sub DataGridView1_SortCompare( _
ByVal sender As Object, ByVal e As DataGridViewSortCompareEventArgs) _
Handles DataGridView1.SortCompare
' Try to sort based on the contents of the cell in the current column.
e.SortResult = System.String.Compare(e.CellValue1.ToString(), _
e.CellValue2.ToString())
' If the cells are equal, sort based on the ID column.
If (e.SortResult = 0) AndAlso Not (e.Column.Name = "ID") Then
e.SortResult = System.String.Compare( _
DataGridView1.Rows(e.RowIndex1).Cells("ID").Value.ToString(), _
DataGridView1.Rows(e.RowIndex2).Cells("ID").Value.ToString())
End If
e.Handled = True
End Sub
설명
이 이벤트는 속성이 설정되지 않고 속성 값false
이 DataSource 인 VirtualMode 경우에만 발생합니다.
이 이벤트는 정렬 중인 열의 셀 쌍을 비교합니다. 발생만 클릭할 때 사용 하 여 열 헤더를 SortMode 속성 값 Automatic를 호출 하는 경우 또는 Sort(DataGridViewColumn, ListSortDirection) 오버 로드. 인 열에 대해이 이벤트가 발생 하는 경우는 SortMode 속성 값 Programmatic를 통해 직접 정렬 문자를 표시 해야 하는 DataGridViewColumnHeaderCell.SortGlyphDirection 속성입니다.
열이 하나 또는 여러 열에 셀 값을 사용 하 여 행을 정렬 하려면이 이벤트를 사용할 수 있습니다. 사용 합니다 CellValue1 및 CellValue2 속성에 지정 된 열에서 셀 값을 비교 하는 Column 속성입니다. 사용 하 여를 RowIndex1 하 고 RowIndex2 속성을 통해 다른 열의 값에에서 액세스를 Rows 컬렉션입니다.
이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.
적용 대상
추가 정보
.NET