By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

Question on SelectAll

P: n/a
In the GotFocus event for several text boxes I include code such as
"txtMyTxtBox.SelectAll". When I tab from textbox to textbox the text in the
textbox that got focus is selected as expected but if I use the mouse to
click on the textbox the text is not selected. I suspect this has something
to do with the order in which the various events fire? In VB6 this worked.

Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
you should use the 'enter' event - not the gotfocus event

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:OV*************@TK2MSFTNGP11.phx.gbl...
In the GotFocus event for several text boxes I include code such as
"txtMyTxtBox.SelectAll". When I tab from textbox to textbox the text in the textbox that got focus is selected as expected but if I use the mouse to
click on the textbox the text is not selected. I suspect this has something to do with the order in which the various events fire? In VB6 this worked.

Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #2

P: n/a
Hal;

I wasn't even aware of that. Let me try you suggestion. BTW, is LostFocus
still the best to use when leaving an object (I want to reset the background
color)

Wayne

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:_i*******************@bignews1.bellsouth.net. ..
you should use the 'enter' event - not the gotfocus event

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:OV*************@TK2MSFTNGP11.phx.gbl...
In the GotFocus event for several text boxes I include code such as
"txtMyTxtBox.SelectAll". When I tab from textbox to textbox the text in

the
textbox that got focus is selected as expected but if I use the mouse to
click on the textbox the text is not selected. I suspect this has

something
to do with the order in which the various events fire? In VB6 this worked.
Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

Nov 21 '05 #3

P: n/a
Hal;

I tried using the enter event as you suggested (and I do see that there is a
corresponding Leave event) but although the event fires and the background
color of the textbox changes, it still does not select the text. In the code
below, the SetBackground sub simply changes the textbox's background color -
to help the user see what object has focus. If I walk through the code I can
see that the SelectAll is being executed but the text does not end up
selected - I'll do some digging about the enter event.

Private Sub txtAssocContactLastName_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtAssocContactLastName.Enter

SetBackground()

txtAssocContactLastName.SelectAll()

End Sub

Wayne

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:_i*******************@bignews1.bellsouth.net. ..
you should use the 'enter' event - not the gotfocus event

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:OV*************@TK2MSFTNGP11.phx.gbl...
In the GotFocus event for several text boxes I include code such as
"txtMyTxtBox.SelectAll". When I tab from textbox to textbox the text in

the
textbox that got focus is selected as expected but if I use the mouse to
click on the textbox the text is not selected. I suspect this has

something
to do with the order in which the various events fire? In VB6 this worked.
Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

Nov 21 '05 #4

P: n/a
* "Wayne Wengert" <wa***************@wengert.com> scripsit:
I wasn't even aware of that. Let me try you suggestion. BTW, is LostFocus
still the best to use when leaving an object (I want to reset the background
color)


That's the best way, IMO. You can use the 'Leave' event too. Be sure
you read and understood the docs on both events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
* "Hal Rosser" <hm******@bellsouth.net> scripsit:
you should use the 'enter' event - not the gotfocus event


This doesn't make any difference, and there is IMHO no reason to prefer
'Enter' over 'GotFocus'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

P: n/a
I looked up the events and, as suggested, either should work. According to
the Help, the events fire in the following sequence:

============= From Help Info ===============
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on),
by calling the Select or SelectNextControl methods, or by setting the
ContainerControl.ActiveControl property to the current form, focus events
occur in the following order:

Enter
GotFocus
Leave
Validating
Validated
LostFocus
When you change the focus by using the mouse or by calling the Focus method,
focus events occur in the following order:

Enter
GotFocus
LostFocus
Leave
Validating
Validated
==========================================

In my case, neither Enter nor GotFocus select the text - Weird?

Wayne
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:OV*************@TK2MSFTNGP11.phx.gbl...
In the GotFocus event for several text boxes I include code such as
"txtMyTxtBox.SelectAll". When I tab from textbox to textbox the text in the textbox that got focus is selected as expected but if I use the mouse to
click on the textbox the text is not selected. I suspect this has something to do with the order in which the various events fire? In VB6 this worked.

Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne

Nov 21 '05 #7

P: n/a
MAybe so - I was just going by MSDN recommendations to use 'Enter' over
GotFocus

Maybe if he adds 'selectall() ' to the click event as well ?? - would that
solve the OP's problem ?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2p************@uni-berlin.de...
* "Hal Rosser" <hm******@bellsouth.net> scripsit:
you should use the 'enter' event - not the gotfocus event


This doesn't make any difference, and there is IMHO no reason to prefer
'Enter' over 'GotFocus'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #8

P: n/a
* "Hal Rosser" <hm******@bellsouth.net> scripsit:
MAybe so - I was just going by MSDN recommendations to use 'Enter' over
GotFocus


OK, you are right. There is a note in the docs.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #9

P: n/a
For some reason - this will work sometimes: do focus() statement first
just before the SelectAll() statement, do a Focus() statement

Does anyone have any suggestions regarding what is happening here and/or
ways to get the text selected when a mouse is used for changing focus?

Wayne


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
Nov 21 '05 #10

P: n/a
Hal,

Thanks for that idea. It didn't work in my case. FYI, if I add another
SelectAll in the click event that does work - but I have over 25 forms, some
with 20+ text boxes - that is a lot of extra code. Do you know if this is
fixed in VSNET 2005?

Wayne

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:1s*******************@bignews1.bellsouth.net. ..
For some reason - this will work sometimes: do focus() statement first
just before the SelectAll() statement, do a Focus() statement

Does anyone have any suggestions regarding what is happening here and/or ways to get the text selected when a mouse is used for changing focus?

Wayne


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.