Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Datagrid Keypress Event Help (VB.NET)


Does anyone know how to use a keypress event with the data grid? If i am binding a datatable to the datagrid, the keypress event doesn't work when the user enters data in a row. I really need to have a keypress event.

Thanks,

Jeff




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Make Keypress Event In Datagrid
1. if i press return on data grid it will move to next record
2. what ascii number for alt in vb


DataGrid's Specific Column Keypress Event
Hi!
i am using DataGrid to display records. I want to update records by editing. in one specific column(Ex: Status) the default data is 'P' . when i press 'c' i want to control the keypress as upper case. Means if i press 'c', it should become 'C'. then i want to check it in beforecolupdate event.

Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
Dim Char As String 'C=67
   Char = Chr(KeyAscii)
   KeyAscii = Asc(UCase(Char))
End Sub

Private Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
Dim sR$, sC$ 'C=67 'R=82
Dim colpos As Byte
sR = Chr(82)
sC = Chr(67)
colpos = (DataGrid1.Columns("Status").ColIndex)

If ColIndex = colpos Then
    If ((DataGrid1.Columns("Status").Value <> sC) And (DataGrid1.Columns("Status").Value <> sR)) Then
         Cancel = True
         MsgBox "You must enter either 'C' OR 'R' only.", vbCritical, "Error in Entry"
      End If
   End If
End Sub

the problem is keypress event works for all colums. BeforeColUpdate event is also not working as i want.
if i modify only Status column then, BeforeColUpdate event is working.
So my question is how to control one specific column's value to upper and check it, because i am modifying 3 columns and checking only one column.
except this problem update is working . only thing is i have to enter Capital 'C' manually.

Help me
thanks
>>>>>>>>>>>>>>>>>



Edited by - sreddy on 4/5/2005 9:18:41 AM

KeyPress Event And TextBox Change In Same Private Event
First off, thank you for this forum...I'm extrememly new so be kind as I know this is a simple task but I'm stuck off in the weeds.

My goal is as someone enters an IP address octet in a textbox, when they get to either 3 characters entered or press the "." key, it will move them to the next octet textbox. I figured how to do it as a keypress event or by text length but how do I monitor both?

I've tried the following:

Private Sub txtIPentry1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIPentry1.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(46) Or txtIPentry1.Text.Length > 2 Then
            e.Handled = True
            txtIPentry2.Focus()
        End If
    End Sub

I just don't know how to combine a txtIPentry1_TextChanged and txtIPentry1_KeyPress event into the same set of code.

Thanks for helping the newbie....

KeyPress Event && MouseDown Event
I'm writing a program that is designed for quick navigation using
specific buttons on the keyboard. In doing this, I have added a
KeyPress event for every control on the form to intercept the key
pressed and pass it to a standard subroutine that identifies what
action should be taken.

Unfortunately, I have a web-browser contol on the form and the
webbrowser does not include a KeyPress event.

I need some way to intercept keypress and mousedown events for the
webbrowser - my thought was to put a control that has these events on
top of the webbrowser, but I have been unable to find a control that
can be transparent while also sitting on top of a webbrowser - the
imagebox control will be transparent, but for some reason it always
falls behind the webbrowser even when I force it to the Front.

my second thought is to trap key press and mouse click events from
within the html pages I am showing in the webbrowser and then passing
them along to vb - but I don't have the slightest clue how to do that,
or even if it can be done.

Does anyone have any ideas on a soltion to this problem?

any help would be appreciated.

thanks.

Trevor Fairchild

The Keypress Event
Could somebody explain to me the code for a keypress event. Just a one liner is all im looking for if possible eg:
Private Sub vbKeypress_1
MsgBox "You have pressed the number 1"

I would like to be able to assign shortcut functions to fire events when a number is pressed 1 - 9.
Thanks for any suggestions

Keypress Event
Hello, I'm trying to capture the enter key when pressed in keypress procedure that will do the same thing as the OK_Click procedure? thank you for any information given.

KeyPress Event- How To
I am a newbie as far as VB is concerned. I am making one calculator program, can anyone tell me how to make Keypress event code and how to integrate it with click event. Like when user click on button captioned 1,it should show 1 as label1 caption and when user presses 1 key on keyboard,same event should occur.

Thanks in advance.

KeyPress Event
Hi I have a bit of code I want run when a value is entered into a Text Box.

I tried - LostFocus() event but that doesnt work
e.g. User types in a Number and when its entered it retrieves a Name from SQL server that relates to the number.
I was thinking of putting it in for a KeyPress (probably TAB) Event but I dont know
How do you specify which Key - do you need the ASCI Code or is there a better event for doing this

KeyPress Event
Hey all,

I am trying to run a keypress event for some command buttons on a form. I have the problem that I have a textbox that requires a name typed into it on the form. Everytime i try and use the keypress on the form I can't type a name into the text box. Below is the code i'm using for the keypress, can someone please help me on how to change the code so i can still use the keypress event and type in the text box. Thanks.

If KeyAscii = 67 Or KeyAscii = 99 Then
cmdCalculate.SetFocus
cmdCalculate_Click
ElseIf KeyAscii = 76 Or KeyAscii = 108 Then
cmdClear.SetFocus
cmdClear_Click
ElseIf KeyAscii = 88 Or KeyAscii = 120 Then
cmdExit.SetFocus
cmdExit_Click
End If

I have the KeyPreview form property set to true as well.

Please help.

Thanks to everyone.

Cam.

KeyPress Event
Anyone know how to detect KeyPress events within an input box?

Thanks

KeyPress Event
I am using a Form_Keypress(KeyAscii as Interger).

For some reason when ever i hit a NUMBER on the Keypad or even along the tope of my keyboard, i get weird numbers.

Example: 4 = 52.

Any reason for this? Do have have to do a long if..else statement in order to get the numbers i need to show up?

Ulysses

Keypress Event
Hi,

I am running a motor until user press any key. i am using keypress event.

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii <> 0 Then ' any any key was pressed
mblnCancel = True
mMoveCancel = True
End If
End Sub

so, i am using a while loop until this boolean variables becomes true. so, when user press any key this boolean will become true and motor will stop.

now, the problem is... when user press "Enter" key then This "Run" button that i am using to run the motor is called again because of Default button.

i made All buttons "Default property as false" but, still that button event is re-called.

what is the solution of that Enter and Escape keys.

please help me
thanks

Keypress Event
Im trying to make a text box that when enter is pressed, it triggers an event. I can't seem to find a place that talks about this. Can anyone give a small sample of code and explain it to me?,
Thanks

Keypress Event?
Hello all, I am just learning vb and need some help. I have 2 txtboxes, I only want them to only be able to accept numbers and the total to be displayed in a lbl.caption. I want the user to use the txtbox in any order.

thanks

Lee

Keypress Event
im tryin to prevent the user from entering any text into a text box. this is the code i have. it will not allow them to enter any letter into the text box but will allow them to enter number into the text box.

Code:
Select Case e.KeyChar
Case CChar("A") To CChar("Z"), CChar("a") To CChar("z"), Chr("8")
e.Handled = False
Case Else
e.Handled = True
End Select

Select Case e.KeyChar
Case CChar("0") To CChar("9")
e.Handled = False
Case Else
e.Handled = True
End Select

Keypress Event
Hi all,

I have a bit of a problem with the keypress event which is hard to describe.

I'm not sure if this has anything to do with it but I recently reinstalled Visual Basic. The keypress used to trigger code with the text that is in the text box plus the character of the key pressed.

For some reason now the code doesn't include the character of the key pressed.

ie if I have a blank text box and I press "1"


VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)Label1.Caption = Text1.TextEnd Sub


Label1.Caption=""

Then if I add a "0" ( Text1.Text=10)
Label1.Caption="1"

It's delayed by a keypress???

VB KeyPress Event
Hi,

This seems very simple question for some of you...........

I m using vb as front end tool and in one of my form I have used around 50 combobox and on keyPress event of all that combos I want to execute the same piece of code, which I have written in common module, but as natural on all fifty combobox keyPress event I need to call that coomon method.

Now my question is, Is there any best way to do this? what I mean is using COM technology, can we cut dwon the size of code.

Hope u guys have understood the problem.

waiting for the reply,

Keypress Event By API
Hi, I have two programs. One program sends some keypress event to the 2nd one by sendmessage API. I can do that perfectly but my problem is that the keypress event is triggered twice. 1st I have used sendmessage for keydown then immediately again used sendmessage for keyup in code. To solve my problem I have also tried SendMessageCallback, SendNotifyMessage in place of SendMessage. But nothing worked. Is there anyway to make the keypress event for once by any way.

regardly
Sangit

Keypress Event
hi i was wondering if someone can help me with a query

i want a label to perform a keypress event when clicked

when the label1 is clicked i want the backspace key to perform its action in textbox 1

any help

thanks

KeyPress Event
Hello everybody

I use the Keypress event of a DataCombo Box to search through a table of a database. I then set the value of the DataCombo to a record of the table. The problem is that when the Keypress event handler terminates, the DataCombo Box takes on the value of the Key pressed.
How can I tell the DataCombo Box not to reset the value I set after the event handler terminates?

thx, in advance

George Papadopoulos

KeyPress Event For Tab Key
I want to display data when user presses enter key or Tab key on a text box. It is working well with enter key in the KeyPress evnet using KeyAscii = 13, but does not go to KeyPress event for tab key which is keyascii = 9, just tabs to next textbox. Please suggest!

No Keypress Event...
I'm using the standard browser that comes with the VB wizard, but I want to disable any and all text entry, so no logging in or searching anything is allowed. Unfortunately, the "browser" control doesn't have any key events... How can I stop people from typing in this window, but still allow them to chat in the other windows and access other programs without difficulty?

Keypress Event
I want to use the keypress event on a form so that when the user presses the right or left arrow my cmdNext and cmdPrevious buttons will execute accordingly. If I use the form's keypress event it won't work cause the focus goes into the various textboxes or buttons on the form. How do I do it?

KeyPress Event
Hello ,
How to captuer the up arrow and down arrow in the Keypress event of textbox control.

Keypress Event
I have the following code in a pgm:


Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
MsgBox "Keypress = " & KeyAscii
End If

End Sub


What i do not understand: when i press <Ctrl> + <M> the message box is displayed!

Anyone knows why?

Keypress Event
Is something wrong with the database?
There are a lot of 'cloned' posts and a lot of posts where the entire question is missing. Very strange. Does anyone else have it or is it just my browser or someting.

Keypress Event At An OCX
I am designing my first OCX which is working for my original purposes but I want to add some new features.

At the keypress event I am executing some code but I will like that this code takes in consideration two boolean variables added to keyascii but when I try to type in the keyascii event declaration VB gives a sintaxis error.

How can I create a code for keypress event using more variables than keyascii?

KeyPress Event?
Hello,

What is the best way to code this?....

I have simple math questions (4+5=, 2+6=....) that I want the user to answer and all of the math questions are in a row. After the user answers the question (correctly) I want them to press the "enter key" and then I want the "focus" to go to the next question.. Is there a way to distinguish the "enter key" from all the others on the key board? I have already searched the ASCII boards, but can't figure it out...

All the answers are typed into a text box

Thanks

Don R

Keypress Event
How do you lock out a particular key from an entire form? The apostrophe for example.

Keypress Event
Hello,

Here is my problem.
When the user is on my form and if he / she hits ctrl + enter at the same time, I want certain text from a text box to move to another text box.

So im thinking I would do this is a form1_keypressevent??

enter key is chr(13) but what is the ctrl key?


Any help.

Thanks.

Keypress Event Help
Hello, we are trying to make a game application where one of the users presses a button when he/she knows the answer.

Here is the code we have experimented with:

If Chr(KeyAscii) = "a" Or Chr(KeyAscii) = "A" Then
msgbox "you pressed A"

End If

this code snippet works in a new project, but for some reason it will not work in ours.
This might be because there are other procedures going on
I.E. a timer we have counting down. Please help us if you know how we can make this work properly.

KeyPress Event
Hi everyone!
I am actually building a calculator in VB; actually the program is implemented only by mouse events, but i'd like to add keyboard support; for example, if the user presses the "9" button on the keyboard, then the program calls the number9MousePressed Sub.
I also want to implement it without changing all buttons' code; how can i do that?
Thnks

Alessandro

Keypress Event
I want response if the keys pressed = ctrl and ?

IE..
If keypress = ctrl & ? then
load form
end if

What are the askii keys for those two suckers
and can they be combined so both heys have to
be pressed to trigger the event?

Wayne

KeyPress Event While Another App Run
Hi All
I need to use keypress event while the ppt file run, in order to change to another ppt file. In short , what the code suppose to do is that: when a user press key 49 (that's '1') pp1.ppt start running, if the user want to stop pp1.ppt and start pp2.ppt he press '2' , and the other way round.
The code below gives me the right ppt file running, but the second keypress event is 'useless' since on the screen there's the ppt file run.
Now, how can i jump from one ppt file to another, with the keypress event?

CODEOption Explicit
Option Base 1
Dim objPP As PowerPoint.Application
--------------------------------------
Private Sub Form_KeyPress(KeyAscii As Integer)

Set objPP = New PowerPoint.Application
Dim PP As PowerPoint.Presentation
Dim str As String
DoEvents

Set objPP = New PowerPoint.Application
objPP.Visible = True

Select Case KeyAscii
Case 49
  str = "D:PPppt1.ppt"
Case 50
  str = "D:PPpp2.ppt"
End Select

Set PP = objPP.Presentations.Open(str, True)
With PP
    .SlideShowSettings.Run
End With

End Sub

Tab Keypress Event
Is it possible to capture the "tab" keystroke?  There seems to be a keyascii value for the tab key but if I put a breakpoint in the keypress event for a certain control, the breakpoint is never reached.

How does one capture this event?

Thanks!



ciao for niao!

AMACycle

American Motorcyclist Association
www.ama-cycle.org

KeyPress Event
Hey everyone. I have an easy question in regards to VB. I am trying to get a form to load another form when I press F3 (KeyAscii of 114 I believe). I've tried an If/Then, but to no avail.... Any suggestions?

Thanks!



Edited by - JMan0948 on 6/2/2004 6:46:23 PM

Keypress Event !
Issit possible to press two keys at the same time ( in the keyboard), just like the piano?

Keypress Event Of Ctl+alt+del
i want to trap key press event of ctl+alt+del keys in windows nt thru an appication.
the application should be such that on pressing those keys in combintaion application should not got task manager.focus to remain in the form where the event occured until a condition or an event occurs.pl help

Start Sub From Keypress Event
I have a function that looksup a value from a listbox when a button is clicked. It works fine.

Command1_Click()
SearchData
End Sub


When I place this in the Keypress event it doesn't run the function

Text1_Keypress()
SearchData
End Sub


SearchData()
Dim S as string
s=Text1.text

//Rest of code(Works fine)

End Sub

I want search to work as user types in each charactor so that is why I want the keypress event.

Question About Keypress Event?
I use Keypress event of textbox to input two vector A(i) and B(i)
(i=1 to n),put n into text5. I want vector A's elements appear in text3, vector
B's elements in text4, but it's not true. Please corect my code

My code :


Code:
Option Explicit
Dim A(1 To 100) As Integer
Dim B(1 To 100) As Integer
Dim i As Integer
Dim so As String
Dim n As Integer ' So phan tu nhap vao o text5

Private Sub Command1_Click()
n = Val(Trim(Text5.Text))
For i = 1 To n
Text3.Text = Str(A(i))
Text4.Text = Str(B(i))
Next i
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Static DecimalPointUsed As Integer
Select Case KeyAscii
Case Asc("0") To Asc("9")
so = so + Chr$(KeyAscii)
Case Asc(".")
If DecimalPointUsed Then
KeyAscii = 0
Else
DecimalPointUsed = True
so = so + Chr$(KeyAscii)
End If
DecimalPointUsed = False
Case Asc(",")
Case Asc(" ")
If so <> "" Then
i = i + 1
A(i) = Val(so)
so = ""
End If
Case Else
KeyAscii = 0
Beep
End Select
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
Static DecimalPointUsed As Integer
Select Case KeyAscii
Case Asc("0") To Asc("9")
so = so + Chr$(KeyAscii)
Case Asc(".")
If DecimalPointUsed Then
KeyAscii = 0
Else
DecimalPointUsed = True
so = so + Chr$(KeyAscii)
End If
DecimalPointUsed = False
Case Asc(",")
Case Asc(" ")
If so <> "" Then
i = i + 1
B(i) = Val(so)
so = ""
End If
Case Else
KeyAscii = 0
Beep
End Select
End Sub

thanks

KeyPress Event Problem
Hi,


Code:
Private Sub txtLabor_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdAddLabor_Click
End If
End Sub
The problem is that a TextBox does not recognize ENTER without modifiers. The event does not fire. If I press CTRL+ENTER however it returns ASC(10).

How can I get it to recognize ENTER ASC(13) on its own?

Best regards,
AstroTux.

KeyPress Event.... {for Webbrowser}
hi, im building a internet/windows explorer type of program. what i need help with is i know that when the webbrowse (wb) is navigating through the internet and the user hits the backspace key, the wb goes back to where it previously was. what im trying to do is get the same effect while the wb is navigating through the harddrive, but unfortunantly the backspace effect doesnt work, so i guess i would have to use a keypress function? but the wb doesnt have that function, so how do i go about getting this??

thanks

DatePicker KeyPress Event
hi
KeyPress event in the DatePicker control doesnt work .. why ?

help me please

Textbox (keypress Event)
I have designed a form with several textboxes.
the user has to be able to switch to the next textbox (according taborder) by pressing both TAB and ENTER.
TAB is no problem (default) but to capture the ENTER -key I use the KeyPress event like this:


Code:
If KeyAscii <> 13 Then Exit Sub

SendKeys (vbTab)

This works but I the pc-speaker makes an anoying [u]sound 'tinggggg'.[/U}

Any ideas?

Thanks Patricktingggg

On Click And Keypress Event
the button I have works on 'on_click'
the code is behind this, but I also want that it workt if you press the enter-button.
how do you do this? something with keypress? but where do I have to put this and how do I let know that it is the enter-button?

Form KeyPress Event
Hi all,

I am working on a project that uses Barcode Scanners. The barcode scanner is a keybord type scanner which simply sends key strokes to the active window.

After examining the Ascii codes that the barcode sends, I realized that it uses keyascii 13 for the terminator ( EOF ) . So I thought that setting a Keypreview=True of the form and catching the ascii characters till hitting keyascii=13 would provide me the Barcode code and it worked but not exactly the way I thought :)

My question and so the problem is :

This form also contains Command buttons. So the keyascii=13 results in pressing one of these command if they have the focus.

I tried to stop this happening by setting keyascii=0 whenever keyascii=13 detected but didn't work.

How can I prevent this from happening ? Any ideas?

Thanks.

Combo Box KeyPress Event
I am using the keypress event for a combo box. when the user presses a key i want to check if it is a valid key, if it is valid, concatenate it to the end of the text in the combobox. The problem with this is that when "f", for instance, is pressed the code will recognize it as a valid key and then put it in the combobox. the keypress event code will complete and then the combobox will read "ff". then if "g" is pressed the combobox will read "ffgg". I understand why this is happening, i just can't get around it.

Form KeyPress Event
Will someone please tell me why I canít get this to work by pressing the Enter key? It works with the cmdUpdate button. When I press the Return key, it just clanks and nothing happens.

I tried this in the Form KeyPress Event:

If KeyAscii = vbKeyReturn Then

(code below)

End If






Private Sub cmdUpdate_Click()


Dim Control As Control

'Some integers to hold values
Dim i As Integer, Index As Integer

'Create a new instance of the recordset
Set oRs = New ADODB.Recordset
'Open the Scale table
oRs.Open "Transactions", oCn, adOpenDynamic, adLockOptimistic, adCmdTable

'Add a new record
oRs.AddNew
'Add Set the fields in the new record equal to their respective
'textbox values
oRs!Tag = txtFields(0)
oRs!FirstName = txtFields(12)
oRs!LastName = txtFields(11)
oRs!Class = txtFields(1)
oRs!Description = txtFields(2)
oRs!Date = txtFields(13)
'Update the recordset
oRs.Update

'Close the recordset
oRs.Close
'Destroy the recordset
Set oRs = Nothing

'Clear all the controls
For Each Control In Me.Controls
If TypeOf Control Is TextBox Then Control.Text = ""
Next

txtFields(3) = "1" 'set headcount default to 1

txtFields(0).SetFocus 'set focus on the Tag Textbox.

txtFields(13) = Date 'set date in Date textbox

End Sub

Keypress Event Handling
Hey Guys,

Could someone help me out with some sample code that would allow me to detect when the enter key is pressed in a textbox. I've read that I need to configure event handling for the textbox etc. but I'm not sure exactly what that means.

Copyright © 2005-08 www.BigResource.com, All rights reserved