views:

118

answers:

2

when I do :

DataGridViewRow.Rows[index].Selected = true;

it however selects the row but the cursor(focus) is still pointing to the previous row..

When I manually enter in edit mode .. it highlights the cell of previous row..not on the row which done through coding.. However when I select the row through mouse then the cursor (focus) and selection works properly...

How should I manually select the row of datagridvie??

+2  A: 

You set focus by setting the CurrentCell property of the actual DataGridView. Row selection is independent from the control's focus. This is how you should set the focus:

DataGridView1.Focus();
DataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
DataGridView1.CurrentCell = DataGridView1[rowIndex,cellIndex];
GenericTypeTea
Thanks for the solution ...One more thing I have to ask , if I am adding any row how shoulg I scroll the datagridview so that newly added row is in the visible area?
Ashish Ashu
I answered your other questions below. Don't forget to accept my answer if it worked for you.
GenericTypeTea
A: 

Regarding your second question "If I am adding any row how should I scroll the DataGridView so that the newly added row is in the visible area?", just set the FirstDisplayedScrollingRowIndex of the DataGridView to your row's index.

GenericTypeTea