Datagridview 选择了正确的行,但箭头仍然指向第一条记录

dis*_*kid 5 c# datagridview

我已经编程DataGridView,以便在插入新记录时,所选索引将更改为新创建的记录。但箭头仍然指向第一行。这是我使用的 LINQ 代码。

int selectedRowIndex = 0;
DataGridViewRow row = dataGridViewFtpServers.Rows
                            .Cast<DataGridViewRow>()
                            .Where(r => r.Cells["Id"].Value.ToString().Equals(selectedId.ToString()))
                            .First();
selectedRowIndex = row.Index;
dataGridViewFtpServers.Rows[selectedRowIndex].Selected = true;
Run Code Online (Sandbox Code Playgroud)

我怎样才能将箭头指向我的,selectedRowIndex这样我就不会得到这个: 在此输入图像描述

Nic*_*coD 1

黑色三角形光标跟随CurrentRow属性。

当前行属性是只读的,但如 msdn 中所述:

要更改当前行,必须将 CurrentCell 属性设置为所需行中的单元格。