DataGridViewSortCompareEventArgs.RowIndex2 DataGridViewSortCompareEventArgs.RowIndex2 DataGridViewSortCompareEventArgs.RowIndex2 DataGridViewSortCompareEventArgs.RowIndex2 Property


比較する 2 番目のセルを含む行のインデックスを取得します。Gets the index of the row containing the second cell to compare.

 property int RowIndex2 { int get(); };
public int RowIndex2 { get; }
member this.RowIndex2 : int
Public ReadOnly Property RowIndex2 As Integer


2 番目のセルを含む行のインデックス。The index of the row containing the second cell.

次のコード例では、複数RowIndex2列の並べ替えでを使用する方法を示します。The following code example demonstrates the use of RowIndex2 in a multiple column sort. この例は、次の方法で提供される大規模な例の一部です。Windows フォーム DataGridView コントロールで並べ替えをカスタマイズします。This example is part of a larger example provided in How to: Customize Sorting in the Windows Forms DataGridView Control.

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(
    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(), _

    ' 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(), _
    End If

    e.Handled = True

End Sub


このプロパティは、複数の列のセル値に基づいて行を並べ替える場合に便利です。This property is useful when sorting rows based on the cell values in multiple columns.