Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net selstart, sellenght

Posted on 2010-11-18
9
Medium Priority
?
1,520 Views
Last Modified: 2012-05-10
Is there any way to activate the selstart/sellenght for all textbox in form automatically.
0
Comment
Question by:rflorencio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 34166376
You would need to add a javascript function to each textbox's onfocus event to set the selStart and selLength values.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34166385
Can you give more details?

If you want all text to be selected upon entry try something like:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        TextBox1.SelectAll()
    End Sub

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34166393
Hmm...WinForms or WebForms?  =D
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Expert Comment

by:Shaun Kline
ID: 34166438
Good point, which is it?
0
 

Author Comment

by:rflorencio
ID: 34166545
Winforms
0
 

Author Comment

by:rflorencio
ID: 34166563
Instead of defining all GotFocus each textbox, I would do it automatically
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34166655
Two ways:
(1) Add all of them after the "Handles" clause.
(2) Wire them up at run-time using AddHandler().

In both cases, use the "sender" parameter to determine which box fired the event.

Example of #1 with three TextBoxes:
*You can select all of them on the form, hit the lightning bolt, then select the GotFocus() event to add them all at once*
Private Sub AllTextBoxex_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
        Dim tb As TextBox = CType(sender, TextBox)
        tb.SelectAll()
    End Sub

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 34166683
Example of #2 using a recursive routine at Form Load():
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WireTextBoxFocusEvent(Me)
    End Sub

    Private Sub WireTextBoxFocusEvent(ByVal cont As Control)
        For Each ctl As Control In cont.Controls
            If TypeOf ctl Is TextBox Then
                AddHandler ctl.GotFocus, AddressOf AllTextBoxes_GotFocus
            ElseIf ctl.HasChildren Then
                WireTextBoxFocusEvent(ctl)
            End If
        Next
    End Sub

    Private Sub AllTextBoxes_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tb As TextBox = CType(sender, TextBox)
        tb.SelectAll()
    End Sub

End Class

Open in new window

0
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 34166686
You can generalize the function so you can use it for all GotFocus functions for all of your textboxes.
Private Sub GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus ...
        CType(sender, TextBox).SelectAll()
    End Sub

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question