|
-
Aug 9th, 2011, 10:21 AM
#1
Thread Starter
Lively Member
Changing what the enter key does in Datagridview
My employers have to enter data into two columns and they want the enter key to go one column to the right and then when they press it again to go to the next row in the first column. Is this possible?
-
Aug 9th, 2011, 10:46 AM
#2
Re: Changing what the enter key does in Datagridview
The effect is possible, before you code it however, you do realize the Tab key does exactly what you want?
-
Aug 9th, 2011, 10:54 AM
#3
Thread Starter
Lively Member
Re: Changing what the enter key does in Datagridview
Well the problem is that there are four columns in the datagridview but they only need to enter data in the first two columns. Also, they are going to be using a key pad so they want to be able to use the enter key on that.
-
Aug 9th, 2011, 12:22 PM
#4
Re: Changing what the enter key does in Datagridview
The following worked for me:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.DataGridView1.ColumnCount = 4
End Sub
End Class
Public Class DataGridViewEx
Inherits DataGridView
Protected Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
If keyData = Keys.Enter Then
Return Me.ProcessEnterKey(keyData)
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
Protected Shadows Function ProcessEnterKey(ByVal keyData As Keys) As Boolean
If keyData = Keys.Enter Then
Dim address = MyBase.CurrentCellAddress
If address.X = 0 Then
MyBase.CurrentCell = MyBase.Item(1, address.Y)
ElseIf address.X = 1 Then
Dim newY = address.Y + 1
If MyBase.RowCount > newY Then
MyBase.CurrentCell = MyBase.Item(0, newY)
End If
End If
Return True
End If
Return MyBase.ProcessEnterKey(keyData)
End Function
Protected Overrides Function ProcessDataGridViewKey(ByVal e As KeyEventArgs) As Boolean
If e.KeyCode = Keys.Enter Then
Return Me.ProcessEnterKey(e.KeyData)
End If
Return MyBase.ProcessDataGridViewKey(e)
End Function
End Class
In the code, I assume that the first two columns are the columns that will have data entered into them.
-
Aug 9th, 2011, 03:03 PM
#5
Thread Starter
Lively Member
Re: Changing what the enter key does in Datagridview
-
Aug 15th, 2011, 05:56 PM
#6
Thread Starter
Lively Member
Re: Changing what the enter key does in Datagridview
ok, so sorry that i replied to this a week later. but i'm having trouble with this. i put the code into my program and it isn't working.
-
Aug 15th, 2011, 06:10 PM
#7
Thread Starter
Lively Member
Re: Changing what the enter key does in Datagridview
so i have tabs with 20 datagridviews all with multiple columns with lots of formatting. so i'm wondering if there is a way to change the enter key without creating a custom dgv. Is there another way?
Last edited by barnaby; Aug 15th, 2011 at 11:13 PM.
-
Aug 15th, 2011, 11:34 PM
#8
Thread Starter
Lively Member
Re: Changing what the enter key does in Datagridview
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
|