473,769 Members | 5,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13897
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(B yRef msg As
System.Windows. Forms.Message, keyData As System.Windows. Forms.Keys) As
Boolean
If msg.WParam.ToIn t32() = 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.ProcessC mdKey(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.Ole Db

Public Class Form1
Inherits System.Windows. Forms.Form

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
' create a connection string
Dim connString As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=C:\\Nort hwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection ()
myConnection.Co nnectionString = connString

' create a data adapter
Dim da As OleDbDataAdapte r = New OleDbDataAdapte r("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.DataS ource = ds.DefaultViewM anager
End Sub
End Class

"Foef" <Fo**@discussio ns.microsoft.co m> wrote in message
news:2F******** *************** ***********@mic rosoft.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(B yRef msg As
System.Windows. Forms.Message, keyData As System.Windows. Forms.Keys) As
Boolean
If msg.WParam.ToIn t32() = 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.ProcessC mdKey(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**@discussio ns.microsoft.co m> wrote in message
news:2F******** *************** ***********@mic rosoft.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(B yRef msg As
System.Windows. Forms.Message, keyData As System.Windows. Forms.Keys) As
Boolean
If msg.WParam.ToIn t32() = 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.ProcessC mdKey(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
3094
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 void Page_Load(object sender, System.EventArgs e) { Page.RegisterHiddenField("__EVENTTARGET","SomeButtonOnThePage");
2
1866
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 webusers type a quanity in one of the datagrid textboxes to fire the corresponding "check stock" linkbutton template column. Thanks in advance of any help with this.
5
3136
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 click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the first button, so when the user hits enter, the previous page is served up. Enter should result in...
10
27893
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? Tim
7
62048
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 does not work. How can I capture the cursor left and right keys for processing?
2
1099
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 webusers type a quanity in one of the datagrid textboxes to fire the corresponding "check stock" linkbutton template column. Thanks in advance of any help with this.
0
1397
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 column in the datagrid, i would like the set focus go to the button. how can i do it? Thank you .
0
1233
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 for winforms only as I haven't tried anything like this in ASP... - I've added a boolean property to the form in the General Declarations section:
2
1193
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 the datagrid. Once the user finishes editing the second form, I need to capture an event on the main form with the datagrid when it is back in focus, and re-load the datagrid. My problem is that I cannot find an event which does this. I tried...
0
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.