473,837 Members | 1,468 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 2310
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
12315
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
9931
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
9709
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
2361
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
6366
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
8068
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
1052
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
9843
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
9682
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
10875
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7806
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
7001
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
5669
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.