Solved

UserControl Setfocus

Posted on 2001-09-11
12
1,003 Views
Last Modified: 2007-12-19
I have a usercontrol with one textbox.  I would like a Setfocus method for this usercontrol to set the focus to the textbox, but am under the impression that this method that it is controlled by the extender object.

Is the setfocus method handled by the extender object or can I just create a public method to set focus to the textbox?
0
Comment
Question by:thatsthefactsjac
  • 3
  • 3
  • 3
  • +2
12 Comments
 
LVL 17

Accepted Solution

by:
smozgur earned 50 total points
ID: 6475438
Try using this code in User Control General Declaration

Public Event SetFocus()

And put this code into UserControl_GotFocus

txtName.SetFocus

To click on the control or using SetFocus Event of control focus on text box.

I hope i understand your question.

Suat
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6475683
I dont know if I understood your question.

Is there not a Setfocus event already in a usercontrol. You need to set the tabindex of textbox to 0 in usercontrol.

0
 

Expert Comment

by:ruchir_khanduri
ID: 6475747
Hi,

You cannot use the SetFocus method of the text box in this case.

An Extender object holds properties of the control that are actually controlled by the container of the control rather than by the control itself. The Extender Object's SetFocus method is a method to set the focus to the control.

I hope it will help you.
0
 

Author Comment

by:thatsthefactsjac
ID: 6475775
How do I add a SetFocus method to my UserControl?  When using the ActiveX wizard, it says the method name Setfocus is in use by the extender object.  

Do I create a public method or use the extender object?
0
 
LVL 3

Expert Comment

by:Joebob
ID: 6476805
Private Sub UserControl_GotFocus()
  Text1.SetFocus
End Sub
0
 

Author Comment

by:thatsthefactsjac
ID: 6477213
If I am not mistaken, using the gotfocus event will only allow me to set focus to the textbox when the usercontrol receives the focus by tabbing into the control or the user places focus in one of its child controls.  I would like to explicitly set focus to the control like this:

' input in the usercontrol is not valid
    msgbox "bad input"
    UserControl1.SetFocus

When using the ActiveX wizard, it says the method
name Setfocus is in use by the extender object.  

Do I simply create a public method named 'SetFocus' or use the extender object?

Sorry about any confusion
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:Joebob
ID: 6477344
Let me re-iterate my very simple post.  Do it just like I showed above and it will work.  Here is my exact code for standard EXE and the UserControl.  You don't need to overload (not possible) the SetFocus method or deal with the Extender object.  The below code will work if the person sets focus to the usercontrol with the mouse, tab, or via code.

STANDARD EXE
Private Sub Form_Click()
  UserControl11.SetFocus
End Sub

USERCONTROL OCX
Private Sub UserControl_GotFocus()
  Text1.SetFocus
End Sub
0
 
LVL 17

Expert Comment

by:smozgur
ID: 6477623
Joebob, i have already suggested txtname.SetFocus in UserControl_Gotfocus but unfortunately thatsthefactsjac has no comment for my comment. I think we have something wrong.

Regards.
suat
0
 
LVL 3

Expert Comment

by:Joebob
ID: 6477695
smozgur, I read your comment above and ask exactly why you have declared a Public Event SetFocus().  This line has no function regarding setting the focus to the textbox contained within the usercontrol.

thatsthefactsjac, the reason that the ActiveX Wizard says the SetFocus method is in use is because VB will handle firing the UserControl_GotFocus event for you.  You do not need to declare a SetFocus method because VB Automatically calls UserControl_GotFocus absolutely anytime that the SetFocus method is called.  FYI, the SetFocus method is called behind the scenes when a user clicks in the area or uses tab, it is also called (obviously) whenever you explicitly called.
0
 

Author Comment

by:thatsthefactsjac
ID: 6477792
Sorry guys, im not sure what I was thinking.....

smozgur, you provided the answer some time ago, but I was confused as to what the public event was for...


Joebob, thanks for your comment regarding the extender object.  That is part of what I was looking for...I have created a question to award you point as well

sincerely sorry about the trouble,
jac
0
 
LVL 17

Expert Comment

by:smozgur
ID: 6477810
Joebob, yes you are right. No need to set an Event for SetFocus. It is my mistake. Thanks for warning.

thatsthefactsjac, thanks for grading second correct part of my comment.

with my best regards.
Suat
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6478422
I hope when you set the tabindex of textbox to 0, it should set focus to textbox, whenever you call Usercontrol1.Setfocus, no need to set it manually in Gotfocus event.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now