473,396 Members | 1,760 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 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 1194
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*******@discussions.microsoft.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*********@hotmail.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*******@hotmail.com> schrieb
On Thu, 04 Dec 2003 06:22:08 GMT, "Charles May"
<qu*********@hotmail.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*******@freenet.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*******@freenet.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*******@freenet.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.refresh
theform.thecontrol.focus

--
Armin

Nov 20 '05 #10
* "Armin Zingler" <az*******@freenet.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.refresh
theform.thecontrol.focus


_Inside_ the form's implementation.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #11
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.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.refresh
theform.thecontrol.focus


_Inside_ the form's implementation.


Why? Does it have to?
--
Armin

Nov 20 '05 #12
* "Armin Zingler" <az*******@freenet.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.refresh
theform.thecontrol.focus


_Inside_ the form's implementation.


Why? Does it have to?


Now I am your boss: How to do that?

;-)))

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #13
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
>
> But it may help to avoid ugly 'Activated' hacks to execute
> code after showing the form.

theform.show
'theform.refresh
theform.thecontrol.focus

_Inside_ the form's implementation.


Why? Does it have to?


Now I am your boss: How to do that?

;-)))


To do what?
--
Armin

Nov 20 '05 #14
* "Armin Zingler" <az*******@freenet.de> scripsit:
>> But it may help to avoid ugly 'Activated' hacks to execute
>> code after showing the form.
>
> theform.show
> 'theform.refresh
> theform.thecontrol.focus

_Inside_ the form's implementation.

Why? Does it have to?


Now I am your boss: How to do that?


To do what?


See first line in this post (better: "directly after the form is
shown").

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #15
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
>>> But it may help to avoid ugly 'Activated' hacks to execute
>>> code after showing the form.
>>
>> theform.show
>> 'theform.refresh
>> theform.thecontrol.focus
>
> _Inside_ the form's implementation.

Why? Does it have to?

Now I am your boss: How to do that?


To do what?


See first line in this post (better: "directly after the form is
shown").

> theform.show
> 'theform.refresh
> theform.thecontrol.focus

--
Armin

Nov 20 '05 #16
* "Armin Zingler" <az*******@freenet.de> scripsit:
>>>> But it may help to avoid ugly 'Activated' hacks to execute
>>>> code after showing the form.
>>>
>>> theform.show
>>> 'theform.refresh
>>> theform.thecontrol.focus
>>
>> _Inside_ the form's implementation.
>
> Why? Does it have to?

Now I am your boss: How to do that?

To do what?


See first line in this post (better: "directly after the form is
shown").

>> theform.show
>> 'theform.refresh
>> theform.thecontrol.focus


Yep. After replacing 'theform' with 'Me'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #17
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
>>>>> But it may help to avoid ugly 'Activated' hacks to execute
>>>>> code after showing the form.
>>>>
>>>> theform.show
>>>> 'theform.refresh
>>>> theform.thecontrol.focus
>>>
>>> _Inside_ the form's implementation.
>>
>> Why? Does it have to?
>
> Now I am your boss: How to do that?

To do what?

See first line in this post (better: "directly after the form is
shown").

>>> theform.show
>>> 'theform.refresh
>>> theform.thecontrol.focus


Yep. After replacing 'theform' with 'Me'.


Doesn't work outside.
--
Armin
Nov 20 '05 #18
On Thu, 4 Dec 2003 12:21:28 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
"Pepi Tonas" <Pe*******@hotmail.com> schrieb
On Thu, 04 Dec 2003 06:22:08 GMT, "Charles May"
<qu*********@hotmail.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.


That explains why it sometimes works for me and sometimes not.
Appreciate your correction. Thanks
Nov 20 '05 #19

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

Similar topics

5
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...
2
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...
1
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...
12
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...
4
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...
2
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...
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...
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 for...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.