473,324 Members | 2,548 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,324 software developers and data experts.

Catch Enter Key with KeyDown Event in Text Column of DataGridVIew Conrol

I want to catch Enter Key with KeyDown Event in TextColumn of DataGridView Control. When I press Enter in the txtItemCode column, I will check the ItemCode in the Database and other stuffs. I can get other keys but I can't get Enter. When I hit the Enter key, The focus is go to next row same column. How could I catch the Enter Key. I can catch with PreviewKeyDown Event but The Event occur from other columns also. I just want to catch from single column. I already googled but found nothing. Below is my code. Help me please.

Expand|Select|Wrap|Line Numbers
  1. Private Sub g_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles g.EditingControlShowing
  2.     Select Case g.CurrentCell.ColumnIndex
  3.         Case 0
  4.             Dim t As TextBox
  5.             t = e.Control
  6.             t.AcceptsReturn = False
  7.  
  8.             RemoveHandler t.KeyDown, AddressOf txt_KeyDown
  9.             AddHandler t.KeyDown, AddressOf txt_KeyDown
  10.     End Select
  11. End Sub
  12.  
  13. Private Sub txt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
  14.     If e.KeyCode = Keys.Return Then
  15.         Dim t As TextBox = CType(sender, TextBox)
  16.         dtb = rst("select * from customer where customerno=" & Val(t.Text))
  17.         If Not dtb.Rows.Count = 0 Then
  18.             g.Rows(g.CurrentRow.Index).Cells(1).Value = dtb.Rows(0)("customername").ToString()
  19.         End If
  20.     End If
  21. End Sub
Oct 1 '13 #1
0 2038

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David | last post by:
I have a custom control that contains a class that Inherits the panel control. I am trying to catch a keydown event in this class and then supress it from the rest of the control as well as the...
3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
3
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is...
2
by: Helen Trim | last post by:
I am struggling to get the keydown event for checkboxes to work when pressing down arrow and enter. The so-called help talks about overriding the IsInputKey method for the controls, but doesn't...
1
by: dana1 | last post by:
I have a form with several combo boxes in the header used to determine the records that will be displayed on the form. When I tab or enter from the last combo box in the header, I want the focus to...
1
by: kgerritsen | last post by:
I am building an application that will receive input from a barcode scanner. The barcode scanner is configured to append to the front value a single character and hyphen that identify the barcode...
9
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the...
3
by: M K | last post by:
My dg is loaded (from stored procedure) and has 1 record in it. When I press enter on that row it does nothing (I have a breakpoint just inside the code where i check for enter pressed) if...
2
by: lenniekuah | last post by:
Hi Friends, Encounter another interesting problem of practical event. I have used FORM KEYDOWN event to navigate the cursor and on the Primary Key TextBox I tried to validate the input after ENTER...
3
maheshwag
by: maheshwag | last post by:
I have a databound combobox column on DGV I am trying to fire a keys on keydown eventhandller on DGV as below: private void Form1_Load(object sender, EventArgs e) { string...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.