DataGridView navigating to next row

前端 未结 7 813
野的像风
野的像风 2021-01-19 10:42

I have a C# winforms application and I am trying to get a button working that will select the next row in a datagridview after the one curently selected.

The code I

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 11:20

    I prefer this row selection :

    First check if no multiselect : number_of_data Then get the select cell (or row) : row_index

    private void next_click(object sender, EventArgs e)
        {
            int number_of_data = dataGridView.SelectedRows.Count;
            if (number_of_data > 1) return;
    
            int row_index = dataGridView.SelectedCells[0].RowIndex;
    
            if (row_index < dataGridView.RowCount-1)
            {
                dataGridView.Rows[row_index++].Selected = false;
                dataGridView.Rows[row_index].Selected = true;
            }
    
            // Do something 
    
        }
    

提交回复
热议问题