Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
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 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 March 22nd, 2005, 05:30 PM
Friend of Wrox
 
Join Date: Jun 2003
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?

J
 
Old April 6th, 2005, 10:53 AM
Registered User
 
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
IRNBRU

 
Old April 6th, 2005, 11:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Sure.

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

'initially set the focus to the first control
tbcMain.SelectedIndex = 0
txtCompany.Focus()
txtCompany.SelectAll()

"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
Me.ActiveControl.Focus()

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.

J





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





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