开发者

DataGridViewRow Select operation

开发者 https://www.devze.com 2022-12-10 12:44 出处:网络
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 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 开发者_如何学Pythondatagridvie??


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];


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.

0

精彩评论

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