473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Capture ENTER key in vb.net datagrid

hi

can anyone help me how can i capture ENTER keystroke when the cell in
datagrid is in editing mode.

I'm now creating a data entry form with primary key in header and details in
datagrid. So when user key in the details in datagrid, I would like user to
choose product code by pressing ENTER key in the datagrid and a Product Code
dialog will appear for him to choose.

Pls help. Thanks very much.

Regards
Steve
Nov 21 '05 #1
3 13872
Steve,

To capture keypress event in a datagrid you should use the ProcessCmdKey
function.

for example:
Public Class MyDataGrid
Inherits DataGrid

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As
Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
SendKeys.Send("{Tab}")
Return True
End If

OR
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case (Keys.Control Or Keys.M)
Case (Keys.Alt Or Keys.Z)
Case Keys.Delete
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function 'ProcessCmdKey

End Class 'MyDataGrid
Greetinx,
Foef

"Melson" wrote:
hi

can anyone help me how can i capture ENTER keystroke when the cell in
datagrid is in editing mode.

I'm now creating a data entry form with primary key in header and details in
datagrid. So when user key in the details in datagrid, I would like user to
choose product code by pressing ENTER key in the datagrid and a Product Code
dialog will appear for him to choose.

Pls help. Thanks very much.

Regards
Steve

Nov 21 '05 #2
Hi Foef

Thank you very much for your solution. Can you tell me how can i use your
code into my existing project. The code is as below. I'm sorry because I'm
new to VB.NET. I'm using Visual Studio ver 7.1. Is there any sample code I
can download.

Pls help. Thanks.

Regards
Steve

Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Northwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection()
myConnection.ConnectionString = connString

' create a data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from
Customers", myConnection)

' create a new dataset
Dim ds As DataSet = New DataSet()
' fill dataset
da.Fill(ds, "Customers")

' Attach DataSet to DataGrid
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
End Class

"Foef" <Fo**@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Steve,

To capture keypress event in a datagrid you should use the ProcessCmdKey
function.

for example:
Public Class MyDataGrid
Inherits DataGrid

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As
Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
SendKeys.Send("{Tab}")
Return True
End If

OR
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case (Keys.Control Or Keys.M)
Case (Keys.Alt Or Keys.Z)
Case Keys.Delete
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function 'ProcessCmdKey

End Class 'MyDataGrid
Greetinx,
Foef

"Melson" wrote:
hi

can anyone help me how can i capture ENTER keystroke when the cell in
datagrid is in editing mode.

I'm now creating a data entry form with primary key in header and details
in
datagrid. So when user key in the details in datagrid, I would like user
to
choose product code by pressing ENTER key in the datagrid and a Product
Code
dialog will appear for him to choose.

Pls help. Thanks very much.

Regards
Steve

Nov 21 '05 #3
Hi Foef

Thanks very much. I've found the way to create Windows Control Library and
add to my windows application. Thanks again
Regards
Steve
"Foef" <Fo**@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Steve,

To capture keypress event in a datagrid you should use the ProcessCmdKey
function.

for example:
Public Class MyDataGrid
Inherits DataGrid

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As
Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
SendKeys.Send("{Tab}")
Return True
End If

OR
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case (keyData)
Case (Keys.Control Or Keys.M)
Case (Keys.Alt Or Keys.Z)
Case Keys.Delete
End Select
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function 'ProcessCmdKey

End Class 'MyDataGrid
Greetinx,
Foef

"Melson" wrote:
hi

can anyone help me how can i capture ENTER keystroke when the cell in
datagrid is in editing mode.

I'm now creating a data entry form with primary key in header and details
in
datagrid. So when user key in the details in datagrid, I would like user
to
choose product code by pressing ENTER key in the datagrid and a Product
Code
dialog will appear for him to choose.

Pls help. Thanks very much.

Regards
Steve

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthew Wieder | last post by:
Hi - I wanted to capture the enter button on a form since I have a datagrid with the first column being a delete button and if someone hits enter it deletes the first record. I coded: private...
2
by: IST | last post by:
Hello, We have a datagrid in a webform that has item id, template colum with textbox for quanity and template column with link button to check stock. We need to capture the enter key when...
5
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
7
by: Bob Achgill | last post by:
When I use the code for KeyPress to capture pressing a certain key for processing on a form with no Text Box it works. But when I try the same code on my application that has text boxes it does...
2
by: IST | last post by:
Hello, We have a datagrid in a webform that has item id, template colum with textbox for quanity and template column with link button to check stock. We need to capture the enter key when...
0
by: LCH | last post by:
hi i would like to know how to capture a datagrid keypress event. I have form contains of a datagrid with 5 rows and 5 colums and a button. When i press on the enter button at the last row n...
0
by: crferguson | last post by:
I've been looking in every place I can to find a solution for this and I believe I've pieced a solid one together so I thought I'd share since I've found so much help on these groups... This is...
2
bplacker
by: bplacker | last post by:
This seems like a simple question but, obviously, I cannot figure it out. I have a form which comes up with a datagrid, and from this datagrid I open up an edit form with the selected record from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.