Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2008, 05:26 PM
Registered User
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default TextBox Event

Greetings All,

I need a text box in VB 2005 with event behavior similar to the AfterUpdate event in VBA. You enter text in the text box, and the event fires when the enter key is hit. I can't use "KeyPress" because it fires after the first key is pressed (and I need to enter text first). I could use "Leave", but I can't figure out how to get it to respond to the Enter Key and not the Tab key.

A part number will be entered into the text box, and, after the event fires, will bring up the appropriate record from a database table (using "tableadapter...get"). I know VB 2005 will generate a generic toolstrip for this type of search (a parameterized query essentially)-- and this works fine. It builds a text box (for search entry) and a button, which calls the tableadapter. BUT, here too, I can't get the text box to respond to the enter key.

I've written many Access/VBA db apps for work. I'd like to convert them over to VBnet where possible -- this is my first real attempt.
This current project is an interface between a big db table of part numbers (which I left in Access) and a laser marker which etches text on finished parts. It connects through COM to all the functionality of the laser -- and I've got all this working well.

Now if I could just figure out how to make the dang Enter key work!

Thanks for any help.

 
Old October 9th, 2008, 12:43 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can use the KeyDown event and test for the enter key character. I have a search box that does this. Here's the C# code:
Code:
private void txtSearchTerms_KeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        // do stuff here
    }
}
-Peter
compiledthoughts.com
 
Old October 10th, 2008, 10:14 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

I have done similar projects with the enter button inside textboxs, one project is for my own command line project. What I use is the following code:
Code:
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As _ System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
        Select Case e.KeyCode
            Case Keys.Enter
                'code here
        End Select
 End Sub
I think this should help you


------------------------------------------------
Apocolypse2005, I'm a programmer - of sorts.
 
Old October 10th, 2008, 12:56 PM
Registered User
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks all! Both solutions work great!






Similar Threads
Thread Thread Starter Forum Replies Last Post
change TextBox.BackColor property onFocus event drasko ASP.NET 1.0 and 1.1 Basics 8 January 26th, 2009 12:23 AM
TextBox - formattering input after event modelplane Visual Basic 2005 Basics 0 December 10th, 2006 03:06 PM
Set/Assign an Event to textbox from Code TomW Access VBA 0 November 15th, 2006 11:16 PM
how to handle click event for TextBox gagansharma7 General .NET 4 June 26th, 2006 01:18 PM
enter key on textbox, performs button event code?? squeakstar Visual Basic 2005 Basics 4 June 22nd, 2006 05:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.