Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

enable/disable  tab function in vb.net form

Posted on 2009-05-01
3
Medium Priority
?
1,020 Views
Last Modified: 2013-11-26

I want to go thru a form with multiple textboxs and edit the fields as I go. Using the txtbox1.keydown and txtbox1.keypress I seem to be able yo captue the [Enter] key, validate the data and either move to the next txtbox2 if good or display an error message and re-focus on the current txtbox1.  The problem is these methods do not seem to trap the [Tab] key - which then bypasses my edits.  Using the following code I am able to capture the tab key, validate the data but I cannot suppress the key and re focus on the current txtbox...


Any way to not tab here?
Thanks,
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _
                           ByVal keyData As Keys) As Boolean
        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.Tab
                    'MsgBox("Tab Key Captured in the " + Me.ActiveControl.Name + " control!")
 
                    'I can do something based on the active control
                    Select Case Me.ActiveControl.Name
                          case TxtBox1
                               if not  validatedata1() then
                                   DON'T PROCESS TAB KEY!!!  ?????
                               end if
                    end select

Open in new window

0
Comment
Question by:norway77
3 Comments
 
LVL 9

Expert Comment

by:CyberLex
ID: 24283283
DON'T PROCESS TAB KEY!!!  ????? = return true

simple as that

:) cheers
Alex
0
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24296599
How about using the Validating event for the control.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx

If you don't like the input in the textbox, then just set the Cancel property in the CancelEventArgs to true. This prevents focus from being set to another control.
0
 

Author Comment

by:norway77
ID: 24309245
oobayly,
that worked great.
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question