473,606 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT method for form textbox controls

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
2 4333
"Cindy M -WordMVP-" <C.*********@hi speed.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
* Cindy M -WordMVP- <C.*********@hi speed.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 'SelectionLengt h' properties to
select some text.

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

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

Similar topics

1
2067
by: Mad Scientist Jr | last post by:
I'm stuck trying to work with a HTML <SELECT> control and javascript (similar to DualList but that control doesn't offer enough options to totally control the text on the buttons and control, also I don't have c# on this machine to try and modify it).. anyway... I'm trying to get javascipt to select all items in a <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all...
6
3178
by: Sean | last post by:
HI There, I am making the transition from asp to asp .net, I am currenty writing an application that requires a bulk insert from a webform into SQL server, normally I would just create rows of html textboxes and then use the Request.Form.Count property to collect each field. What I would like to know is what is a good way of doing this in asp.net? Do I need to create an array of textboxes or can I do this fro a datagrid?
5
1445
by: Dino M. Buljubasic | last post by:
I am trying to build a daily calendar similar to Microsoft Outlook where a user can select hours of a day using mouse. I have a form that holds a panel which contains user controls each representing an hour of the day (24 hours = 24 user controls). How can I mouse-down, drag, mouse-up select a region (say from 9:00am to 1:00pm)? I was trying to use mouse down/mouse up events and return the tag property of the user controls on down /...
4
3142
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
4
1693
by: Philip Wagenaar | last post by:
I have made a form with a tab that containts groupboxes and those contain checkboxes. When I run the application sometimes the outlining for some groupboxes are not shown, if I switch tabs and back sometimes all outlining is shown and sometimes are not shown. I have no idea what is going wrong. What also is weird is that when I open the form from my main application I can resize the form, even though it is locked, and that when I cut...
3
30115
by: abc my vclass | last post by:
My win-form have many numericupdown controls to applied. But numericupdown control don't like textbox, text box control can automatic selected text when got focus. Is there any method can let me set all numericupdown autoselect text when gotfocus?
8
3570
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
5
1791
by: Ronin | last post by:
I need a little help trying to figure out the last piece of this puzzle. I've got a form with an associated toolbox that will allow a user to drag a control off the toolbox and drop it onto the form. The form instantiates the control using the Activator.CreateInstance method. What I then need to do (and the part I have not figured out) is how to attach a method from that control (a custom data refresh method) to a timer.elapsed...
5
2510
by: lukasmazur | last post by:
Hi I have a problem with using listBox1. I have a two forms form1 and form2. In form1 are controls listBox1, textBox1 and button witch creating object of class Form2. In class Form2 I create a pointer to object of class Form1. I don't known how to use method add(), where can I find it. From Form1 I can add value like this this->listBox1- I cant find it. I have textBox1 on Form1 and I can change text in this control like this ...
0
8045
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...
1
8127
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
8320
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
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...
1
5994
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
5470
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
4011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2458
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
0
1315
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.