disasterkid
disasterkid

Reputation: 7278

Datagridview correct row is selected but the arrow is still pointing at the first record

I have programmed my DataGridView so that when a new record is inserted, the selected index will change to that newly created record. But the arrow is still pointing at the first row. This is the LINQ code I use.

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;

How can I point the arrow to my selectedRowIndex so that I don't get this: enter image description here

Upvotes: 5

Views: 2233

Answers (1)

NicoD
NicoD

Reputation: 1189

The black triangle cursor follows the CurrentRow property.

The current row property is read only but as noted in msdn:

To change the current row, you must set the CurrentCell property to a cell in the desired row.

Upvotes: 1

Related Questions