Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old June 9th, 2004, 03:13 AM
ajaysh81 ajaysh81 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 ajaysh81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to use enter key to move in next control

Hi,
My problem is when user press enter key on vb form then curser move to next control.
suppose i press enter key on textbox1 then my control moves to textbox2.
sample code
private sub text1_keypress(---)
if keyascii=13 then
text2.setfocus
end if
end sub

but if there is 50 controls on my form then i dont like to write code on each control's keypress event.

help me by giving some short code for it

Reply With Quote
  #2  
Old June 9th, 2004, 03:40 PM
dgilbert dgilbert is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 dgilbert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Key Preview

On each form you have a keypreview option, which can be set to true. Then in the keypress event of the form
if it = chr(13) then you move to the next control, or better yet, replace the keypress with a tab keystroke. Hope
that helps!

Reply With Quote
  #3  
Old June 14th, 2004, 03:45 AM
ajaysh81 ajaysh81 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 ajaysh81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
replaced enter ascii val with tab but doesn't work

thanks for u'r reply. That's what exactly i want

but i wrote the following code

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB
KeyAscii = 9
End If

End Sub

but this code does not move cursor from one text box to another textbox.i make forms keypreview to true.I dont want to move focus manually . Above method is best but not working plse do some needful.

Reply With Quote
  #4  
Old June 14th, 2004, 07:17 AM
ajaysh81 ajaysh81 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 ajaysh81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
replaced enter ascii val with tab but doesn't work

thanks for u'r reply. That's what exactly i want

but i wrote the following code

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB
KeyAscii = 9
End If

End Sub

but this code does not move cursor from one text box to another textbox.i make forms keypreview to true.I dont want to move focus manually . Above method is best but not working plse do some needful.


Quote:
Originally Posted by dgilbert
On each form you have a keypreview option, which can be set to true. Then in the keypress event of the form
if it = chr(13) then you move to the next control, or better yet, replace the keypress with a tab keystroke. Hope
that helps!

Reply With Quote
  #5  
Old October 14th, 2004, 01:47 AM
madhdhi madhdhi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 madhdhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
did you find a solution

hey
i am wondering if you found the answer to your question posted here
because i am trying to do the same thing
please post your code for me if you found the solution
thanks for your time
regards
madhdhi




Quote:
Originally Posted by ajaysh81
Hi,
My problem is when user press enter key on vb form then curser move to next control.
suppose i press enter key on textbox1 then my control moves to textbox2.
sample code
private sub text1_keypress(---)
if keyascii=13 then
text2.setfocus
end if
end sub

but if there is 50 controls on my form then i dont like to write code on each control's keypress event.

help me by giving some short code for it

Reply With Quote
  #6  
Old October 20th, 2004, 08:37 AM
Arjun Arjun is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 43 Arjun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 18 sec
Reputation Power: 4
Hi ! try this it works

set keypreview option true in u r form,

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
sendsKeys vbtab
End If

End Sub

i hope it will work in your form..!

Reply With Quote
  #7  
Old October 20th, 2004, 09:21 PM
madhdhi madhdhi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 madhdhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks

Thanks so much.....
but would it work if there are more than one form
should i put it on the module

Reply With Quote
  #8  
Old October 20th, 2004, 10:16 PM
Arjun Arjun is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 43 Arjun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 18 sec
Reputation Power: 4
Yes! put it in a module

Code a function like this )in module)

Public Function TabControl(key As Integer)

If key = 13 Then
SendKeys vbTab
End If

End Function

Pass the keyascii from the form keypress ecent
Private Sub Form_KeyPress(KeyAscii As Integer)
TabControl (KeyAscii)
End Sub

Reply With Quote
  #9  
Old October 20th, 2004, 10:17 PM
Arjun Arjun is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 43 Arjun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 18 sec
Reputation Power: 4
..

..

Last edited by Arjun : October 20th, 2004 at 10:19 PM. Reason: ..

Reply With Quote
  #10  
Old November 17th, 2004, 06:08 PM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,782 Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 42 m 2 sec
Reputation Power: 1081
On using the enter key to move between controls...

I had this problem, and have found (finally) a solution that works:
PrivateSub Form1_KeyDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyEventArgs) HandlesMyBase.KeyDown

If e.KeyCode = 13 Then

SendKeys.Send("{TAB}")

EndIf

EndSub
Of course you still have to set the KeyPreview property on the form to True. I hope this is helpful!
Note: This code is for VB.Net

Reply With Quote
  #11  
Old November 19th, 2004, 11:04 AM
demystify demystify is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 demystify User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi!!.. I dont think that send keys is such a good idea bacause if there would be some other applications which are active at that time, the sendkey would be sent to that particular app.

The best thing for u to do is Arrange all textboxes in array. (Put values on the INDEX of 50 controls, and add code to only one event.. let's say


Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If Keyascii= 13 then
Text1(Index + 1).Setfocus
End if
End Sub

Just be sure that you arange all the Indexes of the controls, in the order of focus..

Hope this is cool!!!

Just Be!
Demystify

Reply With Quote
  #12  
Old November 19th, 2004, 11:26 AM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,782 Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 42 m 2 sec
Reputation Power: 1081
Question

Quote:
Originally Posted by demystify
Hi!!.. I dont think that send keys is such a good idea bacause if there would be some other applications which are active at that time, the sendkey would be sent to that particular app.

The best thing for u to do is Arrange all textboxes in array. (Put values on the INDEX of 50 controls, and add code to only one event.. let's say


Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If Keyascii= 13 then
Text1(Index + 1).Setfocus
End if
End Sub

Just be sure that you arange all the Indexes of the controls, in the order of focus..

Hope this is cool!!!

Just Be!
Demystify

Great idea, but does that mean I need to insert this code in every KeyPress event of every text box? Good thought though... I will have to test that further and see if the send keys creates a problem. I guess I wanted a short way to do it, what can I say?

Reply With Quote
  #13  
Old November 19th, 2004, 02:29 PM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 4
Cool

Quote:
Originally Posted by Lauramc
Great idea, but does that mean I need to insert this code in every KeyPress event of every text box? Good thought though... I will have to test that further and see if the send keys creates a problem. I guess I wanted a short way to do it, what can I say?

But
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)

means that you make an array of Textboxes, in this case Text1(), so just 1 keypress method is needed.

Reply With Quote
  #14  
Old November 20th, 2004, 08:43 AM
demystify demystify is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 demystify User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Lauramc
Great idea, but does that mean I need to insert this code in every KeyPress event of every text box? Good thought though... I will have to test that further and see if the send keys creates a problem. I guess I wanted a short way to do it, what can I say?


Hi, No you would only insert that code in one Keypress event even if you have 50 controls.. because they are considered as one because of the Array nature of the controls..

If All 50 controls are set as array controls like Text1(0),Text1(1),Text1(2), etc.. Then these Textboxes refers to only one Event..

Try creating 4 textboxes which are arrays.. whichever control you would write code to, it would open to only one procedure.

Keep cool!
Demystify

Reply With Quote
  #15  
Old November 22nd, 2004, 04:46 AM
prit_vicky prit_vicky is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Gujarat India
Posts: 30 prit_vicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 41 sec
Reputation Power: 4
Send a message via Yahoo to prit_vicky
Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB
SendKeys "{TAB}"
End If

End Sub

set keyPreview of form to TRUE. and
still you are not getting the focus on next textbox then
check tabindex property of textbox on which you want to move cursor.


if it work then
say
thanx

Reply With Quote