DataGridView navigating to next row

前端 未结 7 803
野的像风
野的像风 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:21

    Select Row and Cell for better solution. This solution move row indicator on DataGridView.

        private void _GotoNext(object sender, EventArgs e)
        {
            int currentRow = DataGridView1.SelectedRows[0].Index;
            if (currentRow < DataGridView1.RowCount - 1)
            {
                DataGridView1.Rows[++currentRow].Cells[0].Selected = true;
            }
        }
    
        private void _GotoPrev(object sender, EventArgs e)
        {
            int currentRow = DataGridView1.SelectedRows[0].Index;
            if (currentRow > 0)
            {
                DataGridView1.Rows[--currentRow].Cells[0].Selected = true;
            }
        }
    

提交回复
热议问题