select the row by up and down arrow key?

Deva

Member
Joined
Feb 10, 2021
Messages
17
Programming Experience
1-3
1622875742232.png


i want select the row by up and down arrow key without clicking mouse
and with input textbox by a keydown method
please help me in vb.net coding
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
I will suggest that you handle KeyDown event for textbox, here you can check e.KeyCode for Up/Down navigations keys.
You should also set e.SuppressKeyPress to True in this case to avoid default navigation in text, it would be confusing if this happens also when DataGridView is navigated.
For DataGridView you can get CurrentRow.Index, and use Rows.GetNextRow/GetPreviousRows method to get new index, notice it will be -1 if there is no next/previous row. Then you can change CurrentCell accordingly.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
For DataGridView you can get CurrentRow.Index, and use Rows.GetNextRow/GetPreviousRows method to get new index, notice it will be -1 if there is no next/previous row. Then you can change CurrentCell accordingly.
If the grid is bound to a BindingSource, which it generally ought to be, then you can call MoveNext and MovePrevious.
 
Top Bottom