DataGridViewSortCompareEventArgs.RowIndex1 DataGridViewSortCompareEventArgs.RowIndex1 DataGridViewSortCompareEventArgs.RowIndex1 DataGridViewSortCompareEventArgs.RowIndex1 Property

定義

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

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

プロパティ値

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

次のコード例は、の使用を示しますRowIndex1複数の列の並べ替えにします。The following code example demonstrates the use of RowIndex1 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(
            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

注釈

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

適用対象

こちらもご覧ください