473,795 Members | 3,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting the correct tabindex

Hi there,

I've got what I hope is a simple problem to solve...

Here's the back story: I have a windows form. On the form is a panel
containing three textboxes. Also on the form is a text box and an ok button.

Here's the problem: On condition A, I want input focus to go to a textbox on
the panel when the form loads. On condition B, I want the input focus to go
to the textbox that's on the form when the form loads. Seems pretty simple.

However, I've tried changing the tabindex of each of the text controls and
setting the focus property of the relevant control on form load, but to no
avail. I know there's got to be a simple way to do this!

Any help is appreciated :-)
Mike
May 30 '06 #1
3 2307
Mike Eaton wrote:
Here's the problem: On condition A, I want input focus to go to a textbox on
the panel when the form loads. On condition B, I want the input focus to go
to the textbox that's on the form when the form loads. Seems pretty simple.


TabIndex only goes so far and, in this case, not far enough.
Youneed to forcibly move focus to another contorl, but you can't do that
in Form_Load. The Form (and hence the Control) isn't visible, so won't
accept focus - you have to wait until the Form appears, which is where
the Activated event comes in.

Try this:

Private m_PendingFocus As Control = Nothing

Private Property PendingFocus() as Control
Get
Return m_PendingFocus
End Get
Set(Value as Control)
m_PendingFocus = Value
End Set
End Property

Private Sub Form_Activated( ... ) Handles MyBase.Activate d
If Not (m_PendingFocus Is Nothing) Then
m_PendingFocus. Focus()
m_PendingFocus = Nothing
End If
End Sub

Private Sub Form_Load( ... ) Handles MyBase.Load
If ConditionA Then
Me.PendingFocus = TextBoxOnPanel
Else
' Do Nothing - the existing Tab Order will do
End If
End Sub

HTH,
Phill W.
May 31 '06 #2
Hi Phil,

I tried the approach you suggested and had no success. Here are some more
details:
The current tabindex is set as:
0 - uxTxtCheckAmoun t : the text box whose parent is the form (and should
have focus most of the time)
1 - the form's OK button
2 - the form's Cancel button
3 - the panel that hosts the other three text boxes. their tabindex is set
3.0.0, 3.0.1, and 3.0.2 according to the Tab Order viewer in the IDE. 3.0.0
is the tabindex of the text box uxTxtRouting that I want to have focus some
of the time.

Here's the relevant code I'm using based on what you suggested:

Private _pendingFocus As Control = Nothing

Private Property PendingFocus() As Control
Get
Return _pendingFocus
End Get
Set(ByVal Value As Control)
_pendingFocus = Value
End Set
End Property

Private Sub ItemValidationF orm_Activated(B yVal sender As Object, ByVal e
As System.EventArg s) Handles Me.Activated
If Not (_pendingFocus Is Nothing) Then
_pendingFocus.F ocus()
_pendingFocus = Nothing
End If
End Sub

Private Sub ItemValidationF orm_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
If (_check.MicrErr or) Then
MsgBox("error.. blah..blah", MsgBoxStyle.Cri tical, Me.Text)
Me.PendingFocus = uxTxtRouting
Else
' text box focused via tabindex
End If
End Sub

The PendingFocus property is being accessed correctly during the activation
event, but the form always appears with the uxTxtCheckAmoun t textbox .

Any ideas?
May 31 '06 #3
Mike Eaton wrote:
If (_check.MicrErr or) Then
MsgBox("error.. blah..blah", MsgBoxStyle.Cri tical, Me.Text)
Me.PendingFocus = uxTxtRouting The PendingFocus property is being accessed correctly during the activation
event, but the form always appears with the uxTxtCheckAmoun t textbox .


Have you tried setting me.PendingFocus /before/ showing the MsgBox?
I don't know for certain (but wouldn't be in the least bit surprised)
if showing a dialog over a Form doesn't cause the Form to get Activated
first...

HTH,
Phill W.
Jun 1 '06 #4

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

Similar topics

20
12308
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 appears as if Mozilla needs to have the focus set on that div in order for the mousewheel to work. That's all that link does. The mousewheel works perfectly in IE without the link. It scrolls the div even if there is a scrollbar on the page. Is...
21
9924
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
8
9708
by: David McDivitt | last post by:
I need to set tabs on java generated pages. Pages have four sections: header, sidebar, body, and footer. The sidebar and body change dynamically. The tab key must go to anchors, fields, and buttons doing all in the header first, all in the sidebar second, etc. A base page contains includes for all the pieces and has the body tag. I am trying to use code pasted below. Help would be appreciated. Thanks <script language="javascript"> <!--
0
2353
by: Stuart Norris | last post by:
Dear Group, I am having a problem setting SocketOptionName.SendTimeout on a client TCPIP application using the sockets in .NET. From the on-line help it is possible to set a SocketOptionName.SendTimeout for sends on TCPIP sockets. In all the tests that I have done with both Async and Sync sends the send returns immediately with the number of bytes sent (< 100 in my messages).
1
6364
by: Rachel Suddeth | last post by:
I have an form where the whole display is a tab control (well, that plus a status bar.) I want to set the focus to the first TextBox on the first TabPage when it loads. I tried to put that into the FormLoad event, but the form still comes up with the focus on the tab for the first tab page. Anyone know how to do this? Here is what I tried (but simplified)... ----------------
7
8063
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 when the form is loaded. The textbox cannot be the first in the Tab order, since it's not at the top of the window, and it seems silly to start the tab order at it just to fix this issue. I cannot call control.Focus() from Form1_Load() since...
0
1050
by: Barry Flynn | last post by:
Visual Studio 2005 I have a vague recollection that it is possible to set an option which causes the TabIndex property to be displayed on each control. You could then set the required tabindex number by just clicking on each control in the right sequence. The idea was that doing that would be easier than clicking on each control, going to the Propetties wndow, setting the tabindex, then clicking on the next control etc.
8
2591
by: SSG001 | last post by:
I have follwing function to check if the user enters blank non zero value and other then numbers in the text box // this is in the for loop but tabindex goes ahead and fires the event again how do i prevent the tabindex going to the next textbox <input type="text" name="<?='qty'?> id="<?='qty'?>" onchange="chkqty(this.name);" tabindex="<?=$i?>"> function chkqty(nm){ k=nm.indexOf(''); k=k+1; v=nm.substr(k,p-k); v=parseInt(v,10);
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.