473,397 Members | 2,028 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,397 software developers and data experts.

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 2287
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.Activated
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 - uxTxtCheckAmount : 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 ItemValidationForm_Activated(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Activated
If Not (_pendingFocus Is Nothing) Then
_pendingFocus.Focus()
_pendingFocus = Nothing
End If
End Sub

Private Sub ItemValidationForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If (_check.MicrError) Then
MsgBox("error..blah..blah", MsgBoxStyle.Critical, 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 uxTxtCheckAmount textbox .

Any ideas?
May 31 '06 #3
Mike Eaton wrote:
If (_check.MicrError) Then
MsgBox("error..blah..blah", MsgBoxStyle.Critical, Me.Text)
Me.PendingFocus = uxTxtRouting The PendingFocus property is being accessed correctly during the activation
event, but the form always appears with the uxTxtCheckAmount 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
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...
21
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
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...
0
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...
1
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...
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...
0
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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...
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.