473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting focus

I have a form containing a tab control
I want focus set to a particular text box when the form opens.

However doing this in the load form event
If TabControl1.SelectedIndex = 0 Then
If txtFileName.CanFocus Then
txtFileName.Focus()
End If

End If
I get false from canfocus.

I can do it fine in the tabcontrol.selectedindexchanged event so why
can't I do it in load?

Thanks
Nov 21 '05 #1
2 1562
On 2005-06-08, Jack Russell <ja***@norubbish.tpg.com.au> wrote:
I have a form containing a tab control
I want focus set to a particular text box when the form opens.

However doing this in the load form event
If TabControl1.SelectedIndex = 0 Then
If txtFileName.CanFocus Then
txtFileName.Focus()
End If

End If
I get false from canfocus.

I can do it fine in the tabcontrol.selectedindexchanged event so why
can't I do it in load?

Thanks


Controls have not necessarily completed their initilization in the
form's load event. A control to receive the focus, must be enabled,
visible, and have a handle. You may want to move this code to the forms
activated event - though, you will want to put a flag to make sure this
only happens the first time the activated event fires.

You might also make this happen if you do something like:

Me.Visible = True
Me.Refresh
If txtFileName.CanFocus Then
txtFileName.Focus ()
End If

In your load event. This will force the form to become visible and
redraw it self....

--
Tom Shelton [MVP]
Nov 21 '05 #2
Tom Shelton wrote:
On 2005-06-08, Jack Russell <ja***@norubbish.tpg.com.au> wrote:
I have a form containing a tab control
I want focus set to a particular text box when the form opens.

However doing this in the load form event
If TabControl1.SelectedIndex = 0 Then
If txtFileName.CanFocus Then
txtFileName.Focus()
End If

End If
I get false from canfocus.

I can do it fine in the tabcontrol.selectedindexchanged event so why
can't I do it in load?

Thanks

Controls have not necessarily completed their initilization in the
form's load event. A control to receive the focus, must be enabled,
visible, and have a handle. You may want to move this code to the forms
activated event - though, you will want to put a flag to make sure this
only happens the first time the activated event fires.

You might also make this happen if you do something like:

Me.Visible = True
Me.Refresh
If txtFileName.CanFocus Then
txtFileName.Focus ()
End If

In your load event. This will force the form to become visible and
redraw it self....

Tom,

Thanks,

Had tried it in the activated event to no avail but your second
suggestion worked thanks

Jack
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jesper Dannemamm | last post by:
Hi I am having trouble setting focus on I tried using this script in the usercontrol's page_load sub to set focus on a textbox with the ID = "user_name": Page.RegisterStartupScript("focus",...
20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
2
by: Mystery Man | last post by:
We have an MDI application that is not setting always setting focus to the newly corrected MDI. It is creating the form and it is the topmost but it does not have focus. The code we are using to...
3
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There...
3
by: Brian Henry | last post by:
Hi, I have a bunch of forms in a DLL that I call from my main application. The one form is a login form, and I have the tab order set in the order I want it (password box first, then ok button...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.