Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intercept up and down arrow keys in datagrid

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
Hey Jack,

I know I'm always straying from the ASP.NET world but hope the programming concepts are valid enough that you don't mind. In a Windows Form when a cell inside a datagrid has the focus and the up or down arrow key is pressed the focus moves to the previous or next cell. How can I intercept this event and execute code based on the pressing of the up or down arrow key? The OnKeyUp, OnKeyPress and OnKeyDown are not working as normal in the datagrid. Any ideas?

Kyle
 
Hmmm...now THATS a tricky one. Mainly because the asp.net datagrid is really just an intelligent html table, but I think the visual basic version is a totally different beast.

Have you looked to see if there is an OnFocus or LostFocus event for the rows in the datagrid? That might be easier than trying to track the button keys (assuming that you just want to highlight the selected row or something).

What do you need to trap in the button click?

Jack
 
The button click works well. I can select a row in the data grid using the CurrentRowIndex. I use the current cell changed event to highlight a whole row if you move up or down the grid with the arrow keys. I'm using the grid to display data and sort data by selecting it and moving a row up or down. There is just this little annoying thing. When you reach the top or the bottom of the grid with the arrow key the second time you press the arrow key instead of highlighting the first or last row completely it only highlights the first cell in the row. If I could capture the arrow key event I could control that. I override the ProcessDialogKey to capture the tab key and intercept it's default behaviour on a form. I suspect there is a way to override the keyboard input when the datagrid control has the focus but I don't know the answer yet.

I also would like to have more control over the inherited textbox features in the datagrid cells. I can set a style with TableStyle and set Column features but I would really like to override the default behavior. I don't want the text in the cell to be highlighted or the cursor to be at the end of the text string but have been unsuccessful at getting to those properties. I'm attempting to make a very refined display with sort options.

If I learn any more about this of course I will share.

Kyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top