Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2005, 05:30 PM
Friend of Wrox
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default Trouble setting focus in textbox on tabpage

Has anyone else experienced problems setting the focus to a textbox on the form load or after other events? I have problems when the textbox in placed in a tab control. It doesn't want to receive the focus and I am not sure why. When I debug it, I see that the code for it to receive the focus is hit.

I have been able to work around it (with inconsistent results), but it is frustrating when something supposedly as simple as this causes a problem.

A couple of ways that I have worked around it is to select the tab index before setting the focus. Another way is to set the ActiveControl for the form to the textbox I want the focus to and then set focus to the ActiveControl. This seems like more work than I should have to be doing. Any input?

Reply With Quote
  #2 (permalink)  
Old April 6th, 2005, 10:53 AM
Registered User
Join Date: Apr 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Katsarsj, I wanted to thank you for your solution (maybe not the most effective but it is working and it is not really overhead, it is fast statement) I was stuck in the same way and i was frustated as I knew a similar problem with VB6, .net never solved it??? maybe in 2005 version I hope !

can you please give the snipets of code so I can test your solutions? I managed to test the solution of ActiveControl.

Thank again

Reply With Quote
  #3 (permalink)  
Old April 6th, 2005, 11:22 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts


This worked for one application, but didn't work for another:

'initially set the focus to the first control
tbcMain.SelectedIndex = 0

"tbcMain" is the tab control, "txtCompany" is the textbox.


In case anyone else is interested, here is the code for setting the ActiveControl:

Me.ActiveControl = txtCompany

This worked on a different one. It would seem that since you can't have two controls with the same name on a form, you should simply be able to use txtTitle.Focus() but it doesn't.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Query Focus. eusanpe Access VBA 4 June 4th, 2008 10:20 AM
Setting Focus on a Sub Form Brendan Bartley Access 1 August 8th, 2005 02:41 AM
Setting the Focus BSkelding ASP.NET 1.0 and 1.1 Professional 1 May 12th, 2005 01:40 PM
Setting focus to a web control textbox? hilda ASP.NET 1.0 and 1.1 Basics 2 November 1st, 2003 11:14 AM

All times are GMT -4. The time now is 06:50 PM.

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