开发者

How do i select a row in a dataGridView? (properly with keyboard)

开发者 https://www.devze.com 2023-01-03 08:58 出处:网络
I have the following code. When i refresh my datagrid the row select is still select (note i only have one select row at a time which is why selectIndex is one value and not a list).

I have the following code. When i refresh my datagrid the row select is still select (note i only have one select row at a time which is why selectIndex is one value and not a list).

The problem is when i move my arrowkey up or down it starts from the beginnin开发者_运维技巧g of the datagridview and not the row selected.

            var ret = dataGridView1.Rows.Add(r.orderNo, r.link, r.status);
            dataGridView1.Rows[ret].Tag = r;
            if (r.id == selectIndex)
            {
                dataGridView1.Rows[ret].Selected = true;
            }


This seems to solve your problem:

    void SelectGridRow( int rowIndex )
    {
        _grid.Rows[ rowIndex ].Cells[ 0 ].Selected = true;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消