VB.Net 2003 FORM KEYDOWN problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: VB.Net 2003 FORM KEYDOWN problem

  1. #1
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319

    VB.Net 2003 FORM KEYDOWN problem

    Hi There,
    I am developing VB.NET 2003 window application having problem with the FORM KEYDOWN event.

    Problem with cancelling the keydown event when the data check function return FALSE due to duplicate Debtor ID.
    How to cancel the KeyDown ?
    Code:
    Private Sub FrmDebtor_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    
    	If e.KeyCode = Keys.Tab Or e.KeyCode = keys.Enter Then
    	        If Me.TabIndex = 1 Then
    	 	If FCheckDuplicate = True Then
    			e.KeyCode = Keys.Cancel
    		End If
    	       End If
    	End If	
    End sub
    Last edited by Hack; 12-22-2009 at 08:22 AM. Reason: Added Code Tags
    Cheers,
    Lennie

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try
    Code:
    e.Handled - True
    'or 
    e.SuppressKeyPress = True
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    Thanks Hack,
    Will try it out and if it works will post the script here to share with others.
    Cheers,
    Lennie

  4. #4
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    Hi Hack
    To try out your suggestion, I have modified the script that I initially posted here as per samplel listed below. Surprising, the TAB key action is not working while ENTER is.

    Private Sub FrmDebtor_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    If e.KeyCode = Keys.Tab and ( Me.TabIndex = 1 ) Then
    If FCheckDuplicate = True Then
    e.handled = false
    End If
    End If
    End sub
    Last edited by Lennie; 12-22-2009 at 06:46 PM.
    Cheers,
    Lennie

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Are you sure that when you hit TAB that Me.TabIndex = 1 is true?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    Hi Hack,

    Are you sure that when you hit TAB that Me.TabIndex = 1 is true?

    Yes, it's true. Have you tried it ?
    Cheers,
    Lennie

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You cannot capture the Tab key in the KeyDown (or any other) event; the control processes the Tab key before it fires the event. See if this helps: http://support.microsoft.com/kb/327821
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  8. #8
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    Hi Phil,
    Thank you very much for your information and the URL Link. That are indeed good Christmas present.
    Cheers,
    Lennie

Similar Threads

  1. Replies: 4
    Last Post: 05-21-2009, 10:36 PM
  2. AJAX form tag problem
    By kgarthai in forum AJAX
    Replies: 0
    Last Post: 02-19-2007, 09:31 PM
  3. Replies: 0
    Last Post: 12-11-2002, 06:05 AM
  4. Problem validating form NEED HELP
    By Steve in forum Web
    Replies: 1
    Last Post: 01-04-2002, 04:32 AM
  5. Form Problem In Netscape
    By Dan in forum Web
    Replies: 3
    Last Post: 11-23-2001, 05:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center