DatagridView Select last row

后端 未结 8 2033
你的背包
你的背包 2021-02-14 17:20

I have some trouble with setting the last row in my datagridview selected. I select the last row this way:

if (grid.Rows.Count > 0)
{
    try
    {
        gr         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 17:43

    Try:

    dataGridView1.ClearSelection();//If you want
    
    int nRowIndex = dataGridView1.Rows.Count - 1;
    int nColumnIndex = 3;
    
    dataGridView1.Rows[nRowIndex].Selected = true;
    dataGridView1.Rows[nRowIndex].Cells[nColumnIndex].Selected = true;
    
    //In case if you want to scroll down as well.
    dataGridView1.FirstDisplayedScrollingRowIndex = nRowIndex;
    

    Gives following output: (Last row, scrolled and selected)

    alt text

提交回复
热议问题