|
-
Jul 9th, 2007, 01:21 AM
#1
Thread Starter
Hyperactive Member
[2005] DataGridView - Enter Key
Is there a way to control how a DataGridView responds to an Enter keypress?
Right now, if I edit a cell and press the Enter key, focus goes to the next row. I want to have a choice of staying on the same cell, moving to the next row in the same column, or moving to the next column in the same row.
-
Jul 9th, 2007, 08:54 AM
#2
Re: [2005] DataGridView - Enter Key
Wondering this myself recently and found a good post about this here:
http://forums.microsoft.com/MSDN/Sho...57055&SiteID=1
Hope that helps.
-
Jul 14th, 2007, 02:51 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
I'm still looking for an answer to this one. I want to edit a cell, press Enter, and stay in the same cell - not move to the next row. Sometimes I'll want to move to the next column on the same row.
I suppose I could use SendKeys (does that still exist in VB2005) and send an UpArrow if I'm not on the last row already. But surely there's a better way.
-
Jul 14th, 2007, 03:07 PM
#4
Re: [2005] DataGridView - Enter Key
I can't say that I've really played around with this so I'm sure one of the more experienced programmers could help you further, but the post above didn't give any help? There is this code in there: "Here is the code you need to make the Enter key move the focus to the right:"
I'm sure you'll find your solution. Good luck.
-
Jul 14th, 2007, 03:13 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
That code looks like C or some other language I don't know. Will it be the same in VB?
-
Jul 14th, 2007, 03:16 PM
#6
Re: [2005] DataGridView - Enter Key
-
Jul 14th, 2007, 03:24 PM
#7
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
Cool. Didn't know about the converter.
Will I need to delete my current DataGridView controls from the form and replace them with derived ones or will adding this code to a class do the same thing, with my current DataGridViews?
vb Code:
Public Class dgv
Inherits DataGridView
Protected Overloads Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
Dim key As Keys = (keyData And Keys.KeyCode)
If key = Keys.Enter Then
Return Me.ProcessRightKey(keyData)
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
Protected Overloads Overrides Function ProcessDataGridViewKey(ByVal e As KeyEventArgs) As Boolean
If e.KeyCode = Keys.Enter Then
Return Me.ProcessRightKey(e.KeyData)
End If
Return MyBase.ProcessDataGridViewKey(e)
End Function
End Class
-
Jul 17th, 2007, 12:55 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
I tried something a little simpler (I think). I used SendKeys to send an UpArrow to the grid (except on the bottom row) in the EndEdit event.
The only problem I see is that if you're editing a cell, and then leave the cell by pressing an arrow key (like RightArrow) the UpArrow is still sent. Is there a way to trap this and not send the UpArrow when the EndEdit was fired by another ArrowKey? Maybe a .LastKeyPressed property or something similar?
-
Jul 19th, 2007, 12:34 AM
#9
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
I still don't understand what to do with this code.
What I want is to have a choice of how the Enter key affects the current row and current column. I want 3 choices for when Enter is pressed after editing a cell.
1. Stay in the same cell.
2. Stay in the same column & go to the next row (if it exists).
3. Stay in the same row & go to the next column (if it exists).
Can anyone help with that?
The grid would respond based on the value of CheckBoxes.
-
Jul 23rd, 2007, 01:20 AM
#10
Thread Starter
Hyperactive Member
Re: [2005] DataGridView - Enter Key
Nobody? I tried the code in the suggestion above and it doesn't really work for my situation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|