The grid automatically moves the position of the lower snap when you move up and down.
If you want the selection to go from the top to the button and vice versa, you could handle the grid_KeyDown event to check its position. unfortunately, if you try to move a position, it will be overridden by the gridview Row_Enter event. thus changing the position of the binding source.
In the Grid_Keyup event Grid_Keyup position is already set, so you do not know if the user will simply move to the row, or if he wants to move away from the row. But setting bindingSource.Position here actually works - and is not overridden by the grid.
You can also use DataGridViewRow.Selected = true , but it does not move the main position of the binding. Also, it is not ideal for grids in which the multi selector is turned on.
The ugly truth is that you should use the boolean (as in your own answer) to control whether the line should jump or not. :(
however, you do not need to control it from the PositionChanged event, you can do this by simply handling the grid_KeyDown event:
private bool _changePost; private void dataGridView1_KeyUp(object sender, KeyEventArgs e) { var view = sender as DataGridView; var bs = bindingSource1; if (e.KeyData == Keys.Up) { if (bs.Position == 0 && _changePost) { _changePost = false; bs.MoveLast(); } if (bs.Position == 0 && !_changePost) _changePost = true; } else if (e.KeyData == Keys.Down) { if (bs.Position == bs.Count - 1 && _changePost) { bs.MoveFirst(); _changePost = false; } if (bs.Position == bs.Count - 1 && !_changePost) _changePost = true; } }
It was as clean as I could get it.
source share