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

SELECT method for form textbox controls

P: n/a
Hi all

While working my way through a VB.NET exercise, I came
across something that didn't do what the text said it
should and I'm wondering if it's supposed to behave this
way, or not (and why).

txtNote.Text = "the text"
txtNote.Enabled = True
'txtNote.Select()
txtNote.Select(0, 0) 'deselect text

txtNote is a textbox control on a windows form. As the code
stands, the txtNote control is NOT selected, focus remains
in the control that had the selection when the code is
executed.

If I include the line that's currently commented out, first
selecting the control specifically, then setting the
selection length (doesn't matter what numbers I put in the
function), it works as I'd expect, and focus is in the text
box.

Should it always be necessary to use Select twice - once to
put the focus into the control, once to change what's
selected - or am I missing something?

TIA, Cindy
-- Cindy

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Cindy M -WordMVP-" <C.*********@hispeed.ch> schrieb
Hi all

While working my way through a VB.NET exercise, I came
across something that didn't do what the text said it
should and I'm wondering if it's supposed to behave this
way, or not (and why).

txtNote.Text = "the text"
txtNote.Enabled = True
'txtNote.Select()
txtNote.Select(0, 0) 'deselect text

txtNote is a textbox control on a windows form. As the code
stands, the txtNote control is NOT selected, focus remains
in the control that had the selection when the code is
executed.

If I include the line that's currently commented out, first
selecting the control specifically, then setting the
selection length (doesn't matter what numbers I put in the
function), it works as I'd expect, and focus is in the text
box.

Should it always be necessary to use Select twice - once to
put the focus into the control, once to change what's
selected - or am I missing something?


Do you want to select text or do you want to change the focus?

To change the focus, call the Focus function.
To select text, set the SelectionStart and SelectionLength properties, or
call SelectAll.

--
Armin

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

Nov 20 '05 #2

P: n/a
* Cindy M -WordMVP- <C.*********@hispeed.ch> scripsit:
While working my way through a VB.NET exercise, I came
across something that didn't do what the text said it
should and I'm wondering if it's supposed to behave this
way, or not (and why).

txtNote.Text = "the text"
txtNote.Enabled = True
'txtNote.Select()
txtNote.Select(0, 0) 'deselect text

txtNote is a textbox control on a windows form. As the code
stands, the txtNote control is NOT selected, focus remains
in the control that had the selection when the code is
executed.

If I include the line that's currently commented out, first
selecting the control specifically, then setting the
selection length (doesn't matter what numbers I put in the
function), it works as I'd expect, and focus is in the text
box.

Should it always be necessary to use Select twice - once to
put the focus into the control, once to change what's
selected - or am I missing something?


'Select' without parameters is used to /activate/ the control (its
inherited from 'Control'), the parameterized 'Select' method is used to
select part of the text. You can call the control's 'Focus' method to
focus it and the 'SelectionStart' and 'SelectionLength' properties to
select some text.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.