DatagridView Select last row

后端 未结 8 2010
你的背包
你的背包 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:51

    It's very easy. use: dataGridView.CurrentCell=dataGridView[ColumnIndex, RowIndex];
    dataGridView[X,y]...
    instead of
    dataGridView[Y, X]...

    0 讨论(0)
  • 2021-02-14 17:54

    I know this may be a little late but it may be of use to someone else.

    Have you tried this :

    grid.Rows.Row[grid.Rows.Count -1].Selected = true;

    In my windows app I first used your code in my datagridview and I got the same exception.. and then it came to me at night when I was in my bed (I'm a newbie to programming).

    If I write as : Rows[Rows.count-1] the first row is "0" and "0-1 = -1" so its out of range :)

    Then when I changed my code to Rows.Row[index] it worked! :)


    An alternative if you use c# 3.0 and higher: check out CellAddress(); ;)

    Sincerely

    0 讨论(0)
提交回复
热议问题