473,387 Members | 1,789 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,387 software developers and data experts.

VB.Net - Focus

Hi to all
I am facing this kind of problem.

When i write the following code

TextBox1.Focus()

If the text box already contains any values the cursor will be placed below the first character of the string of textbox.I need to place the cursor at the end of the string in the textbox.
Any one can response me?

Sorry for the bad English.
Jun 13 '07 #1
6 2635
kenobewan
4,871 Expert 4TB
I suggest using client side code. HTH.
Jun 13 '07 #2
Frinavale
9,735 Expert Mod 8TB
Hi to all
I am facing this kind of problem.

When i write the following code

TextBox1.Focus()

If the text box already contains any values the cursor will be placed below the first character of the string of textbox.I need to place the cursor at the end of the string in the textbox.
Any one can response me?

Sorry for the bad English.
This is going to require a lot of JavaScript.
Please see this thread on text box cursor location...I think it may help you.

This may also help you understand how to use JavaScript in .NET


-Frinny
Jun 13 '07 #3
TRScheel
638 Expert 512MB
The others have already started answering this question, but I am wondering, is this a web application? or a desktop application?
Jun 13 '07 #4
Plater
7,872 Expert 4TB
I found this on an msdn forums when looking for javascript selection
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE> Select Test </TITLE>
  4. </HEAD>
  5. <SCRIPT LANGUAGE="JavaScript">
  6. <!--
  7. function selectSomeText(element){         
  8.   var workRange=document.selection.createRange();     
  9.   var allRange=element.createTextRange();     
  10.   workRange.setEndPoint("StartToStart",allRange);     
  11.   workRange.select();
  12. }
  13. function getCaretPosition(element){
  14.                 var workRange=document.selection.createRange();     
  15.                 var allRange=element.createTextRange();     
  16.                 workRange.setEndPoint("StartToStart",allRange);
  17.                 return workRange.text.length;
  18. }
  19. //-->
  20. </SCRIPT>
  21. <BODY>
  22. <form method="GET" name="Login">
  23. <pre>
  24. <input type="type" value ="This is the user name" onclick="selectSomeText(this)" style="width:300px"><br>
  25. <input type="type" value ="abcdefghijklmnopqrstuvw" onclick="alert(getCaretPosition(this))" style="width:300px">
  26. </pre>
  27. </form>
  28. </BODY>
  29. </HTML>
  30.  
You should be able to pull what you need from out of that
Jun 13 '07 #5
Frinavale
9,735 Expert Mod 8TB
I found this on an msdn forums when looking for javascript selection
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE> Select Test </TITLE>
  4. </HEAD>
  5. <SCRIPT LANGUAGE="JavaScript">
  6. <!--
  7. function selectSomeText(element){         
  8.   var workRange=document.selection.createRange();     
  9.   var allRange=element.createTextRange();     
  10.   workRange.setEndPoint("StartToStart",allRange);     
  11.   workRange.select();
  12. }
  13. function getCaretPosition(element){
  14.                 var workRange=document.selection.createRange();     
  15.                 var allRange=element.createTextRange();     
  16.                 workRange.setEndPoint("StartToStart",allRange);
  17.                 return workRange.text.length;
  18. }
  19. //-->
  20. </SCRIPT>
  21. <BODY>
  22. <form method="GET" name="Login">
  23. <pre>
  24. <input type="type" value ="This is the user name" onclick="selectSomeText(this)" style="width:300px"><br>
  25. <input type="type" value ="abcdefghijklmnopqrstuvw" onclick="alert(getCaretPosition(this))" style="width:300px">
  26. </pre>
  27. </form>
  28. </BODY>
  29. </HTML>
  30.  
You should be able to pull what you need from out of that

That could have been very useful when I was trying to implement this!
Of course I always have to do things the hard way first.
I guess that's just how I learn :)

Thanks Plater!

-Frinny
Jun 13 '07 #6
Plater
7,872 Expert 4TB
I just made it better
Expand|Select|Wrap|Line Numbers
  1. function MoveToEnd(element)
  2. {
  3.     var ee=element;
  4.     var eelen =(ee.value.length);
  5.     setCaretTo(ee,eelen);
  6. }
  7. function setCaretTo(obj, pos) 
  8. {
  9.     if(obj.createTextRange) 
  10.     {
  11.         var range = obj.createTextRange();
  12.         range.move('character', pos);
  13.         range.select();
  14.     } 
  15.     else if(obj.selectionStart) 
  16.     {
  17.         obj.focus();
  18.         obj.setSelectionRange(pos, pos);
  19.     }
  20. }
  21.  
Use whatever means you want to get the textbox element (I used .getElementById() to pass in to movetoend)
Jun 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
2
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a...
3
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
1
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
11
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz...
7
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click'...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
3
by: jp2express | last post by:
I have several applications that use panels as screens, but I can *not* seem to set the focus for a Textbox. Panel1.BringToFront() Panel1_Textbox.Focus() ' do something with a control on Panel1...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.