473,653 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting Focus to A Control on a Form

I know I've done this somewhere but I cannot find any example of it in any
of my test code.

I have a form with a Listbox that is filled by a dataset it fills in various
textboxes.

When the form first opens, I have to tab to the listbox so that I can scroll
down the list.

How do I setfocus to the listbox (I know I can change the tab order but I
thought I could move to it with a setfocus method)

Thanks

Charlie
Nov 20 '05 #1
18 1210
Did you try myListbox.Focus ()?

BB
-----Original Message-----
I know I've done this somewhere but I cannot find any example of it in anyof my test code.

I have a form with a Listbox that is filled by a dataset it fills in varioustextboxes.

When the form first opens, I have to tab to the listbox so that I can scrolldown the list.

How do I setfocus to the listbox (I know I can change the tab order but Ithought I could move to it with a setfocus method)

Thanks

Charlie
.

Nov 20 '05 #2
Thanks BB
I had tried that but it didn't work. Then I went back in to see if I had
done something wrong
and found that I had put the code in the wrong routine.

Thanks
Charlie
<an*******@disc ussions.microso ft.com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Did you try myListbox.Focus ()?

BB
-----Original Message-----
I know I've done this somewhere but I cannot find any

example of it in any
of my test code.

I have a form with a Listbox that is filled by a dataset

it fills in various
textboxes.

When the form first opens, I have to tab to the listbox

so that I can scroll
down the list.

How do I setfocus to the listbox (I know I can change

the tab order but I
thought I could move to it with a setfocus method)

Thanks

Charlie
.

Nov 20 '05 #3
On Thu, 04 Dec 2003 06:22:08 GMT, "Charles May"
<qu*********@ho tmail.com> wrote:
Thanks BB
I had tried that but it didn't work. Then I went back in to see if I had
done something wrong
and found that I had put the code in the wrong routine.

You should put it in the Load event of the form, so that focus is
gained as soon as the form is loaded. Make sure the control has the
tabstop property enabled
Nov 20 '05 #4
Cor
Hi Charles,

Is it maybe a webform?

Cor

I have a form with a Listbox that is filled by a dataset it fills in various textboxes.

Nov 20 '05 #5
"Pepi Tonas" <Pe*******@hotm ail.com> schrieb
On Thu, 04 Dec 2003 06:22:08 GMT, "Charles May"
<qu*********@ho tmail.com> wrote:
Thanks BB
I had tried that but it didn't work. Then I went back in to see if I
had done something wrong
and found that I had put the code in the wrong routine.

You should put it in the Load event of the form, so that focus is
gained as soon as the form is loaded. Make sure the control has
the tabstop property enabled


Setting the focus in the Load event does not work because the control must
be visible to gain the focus.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
* "Armin Zingler" <az*******@free net.de> scripsit:
I had tried that but it didn't work. Then I went back in to see if I
had done something wrong
and found that I had put the code in the wrong routine.

You should put it in the Load event of the form, so that focus is
gained as soon as the form is loaded. Make sure the control has
the tabstop property enabled


Setting the focus in the Load event does not work because the control must
be visible to gain the focus.


It will work if you show the form in the 'Load' event handler.

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb
Setting the focus in the Load event does not work because the
control must be visible to gain the focus.


It will work if you show the form in the 'Load' event handler.

;-)


Yep. But bad design in IMHO (load fires the first time before the form is
shown, so it is not necessary to show it because it's just about to be
shown).
--
Armin

Nov 20 '05 #8
* "Armin Zingler" <az*******@free net.de> scripsit:
Setting the focus in the Load event does not work because the
control must be visible to gain the focus.


It will work if you show the form in the 'Load' event handler.

;-)


Yep. But bad design in IMHO (load fires the first time before the form is
shown, so it is not necessary to show it because it's just about to be
shown).


But it may help to avoid ugly 'Activated' hacks to execute code after
showing the form.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schrieb
* "Armin Zingler" <az*******@free net.de> scripsit:
Setting the focus in the Load event does not work because the
control must be visible to gain the focus.

It will work if you show the form in the 'Load' event handler.

;-)


Yep. But bad design in IMHO (load fires the first time before the
form is shown, so it is not necessary to show it because it's just
about to be shown).


But it may help to avoid ugly 'Activated' hacks to execute code
after showing the form.


theform.show
'theform.refres h
theform.thecont rol.focus

--
Armin

Nov 20 '05 #10

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

Similar topics

5
3778
by: Melissa | last post by:
1. Is there a way to programatically remove the focus from the form; ie, so the focus is not on any control on the form? 2. Is there a way to programatically set the focus to the same place as is done when the form opens; ie, the first control in the taborder which is visible, which is enabled and whose tabstop property is True? I have a form with forty two small subforms and I want to code the Enter event of all the subform controls...
2
3648
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl As Control Set MyControl = Screen.ActiveControl MyControl.BackColor = 65280 Tabbing from control-to-control is great. Each time I land on
1
1893
by: Jason | last post by:
I have created a c-sharp app that has keyup, keydown events tied to the form. The form also has some other controls, buttons, labels and 1 custom control that I made which inherits from user control. My problem is ... When I first start the app all my keyboard events work fine and by doing debugging I can see that my form has the focus. After I click on a button or my custom control the focus is shifted to those controls and the keyup,...
12
4887
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function cmdButton1_Clicked() { document.all('txtInput1').focus(); return false; }
4
1919
by: Aung Thu | last post by:
Hi, there! I want to set focus on a control, of which TabIndex is not the first, when a form is loaded. In the form's load event, I have used Control.Focus() but it doesn't not work. The focus is not on the control I set. The focus is always on the control of which TabIndex is 0. Thanks.
2
1904
by: Sridhar | last post by:
Hi, I have a question. I have created a user control which contains a textbox and a button. we will enter some search word in the textbox and hit the button. Then we will get a pop-up with the listbox that contains the matches. Once I select one of the matches, it will close the pop-up and display the selected one in a label control which is also in the user control. Everything is working fine. But I am not getting one thing. After the...
1
2047
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 for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
1
5133
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 for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
7
8051
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...
5
2034
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 information and one that resets the form... The second on, the reset button, i would like to set focus back to the first textbox on the form. I already have an onload in my body, which sets the
0
8283
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
8811
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...
0
8704
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...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
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...
0
4147
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...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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.