DataGridView navigating to next row

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

    try this:

     int nRow;
    private void Form1_Load(object sender, EventArgs e)
    {
    
        nRow = dataGridView1.CurrentCell.RowIndex;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        if (nRow < dataGridView1.RowCount )
        {
            dataGridView1.Rows[nRow].Selected = false;
            dataGridView1.Rows[++nRow].Selected = true;
        }
    }
    

提交回复
热议问题