DataGridViewSortCompareEventArgs 클래스

정의

SortCompare 이벤트에 대한 데이터를 제공합니다.

public ref class DataGridViewSortCompareEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewSortCompareEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewSortCompareEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewSortCompareEventArgs
Inherits HandledEventArgs
상속
DataGridViewSortCompareEventArgs

예제

다음 코드 예제에서는 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

설명

처리할 수 있습니다는 SortCompare 이벤트를 사용자 지정 정렬을 제공 합니다. 이 이벤트에만 발생 경우를 DataGridView.DataSource 속성이 설정 되지 않은 및 DataGridView.VirtualMode 속성이 false. 이 이벤트는 정렬 되는 열에서 셀의 각 쌍에 대해 한 번 발생 합니다. 발생만 클릭할 때 사용 하 여 열 헤더를 DataGridViewColumn.SortMode 속성 값 Automatic를 호출 하는 경우 또는 DataGridView.Sort(DataGridViewColumn, ListSortDirection) 오버 로드. 인 열에 대해이 이벤트가 발생 하는 경우는 DataGridViewColumn.SortMode 속성 값 Programmatic를 통해 직접 정렬 문자를 표시 해야 하는 DataGridViewColumnHeaderCell.SortGlyphDirection 속성입니다.

열이 하나 또는 여러 열에 셀 값을 사용 하 여 행을 정렬 하려면이 이벤트를 사용할 수 있습니다. 사용 합니다 CellValue1CellValue2 속성에 지정 된 열에서 셀 값을 비교 하는 Column 속성입니다. 사용 하 여를 RowIndex1 하 고 RowIndex2 속성을 통해 다른 열의 값에에서 액세스를 DataGridView.Rows 컬렉션입니다.

생성자

DataGridViewSortCompareEventArgs(DataGridViewColumn, Object, Object, Int32, Int32)

DataGridViewSortCompareEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

CellValue1

비교할 첫째 셀의 값을 가져옵니다.

CellValue2

비교할 둘째 셀의 값을 가져옵니다.

Column

정렬할 열을 가져옵니다.

Handled

이벤트 처리기에서 이벤트를 완전히 처리했는지 아니면 시스템에서 처리를 계속해야 하는지를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 HandledEventArgs)
RowIndex1

비교할 첫째 셀이 포함된 행의 인덱스를 가져옵니다.

RowIndex2

비교할 둘째 셀이 포함된 행의 인덱스를 가져옵니다.

SortResult

비교된 셀이 정렬될 순서를 나타내는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보