Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control class and SelectAll 1

Status
Not open for further replies.

ElectricEel

Programmer
Aug 1, 2001
13
US
Within a simple validation loop, I need to SelectAll text within a textbox control when invalid, however SelectAll is not available in the Control class. How can I go about this within the current loop? Pardon my ignorance if the answer is obvious.

Here's what I have:

Private Function ValidateInput() as Boolean
Dim ctlControl as Control
For Each ctlControl In Me.Controls
If TypeOf ctlControl Is TextBox Then
With ctlControl
.Focus()

'select all text in textbox ????

ValidateInput = False
Exit Function
End With
End If
Next
Return True
End Function
 
Try this:
Code:
MyTextBox.SelectionStart = 0
MyTextBox.SelectionLength = MyTextBox.Text.Length
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
MyTextBox.SelectAll() would accomplish the same. My goal is to NOT have to explicitly call each TextBox control but implicitly call them from the Control class within the loop.
 
Just add a couple lines to your code:

Code:
Private Function ValidateInput() as Boolean
     Dim ctlControl as Control
     Dim txtText as TextBox
     For Each ctlControl In Me.Controls
          If TypeOf ctlControl Is TextBox Then
               txtText = CType(ctlControl, TextBox)
               With txtText
                    .Focus()
                    .SelectAll()
                    ValidateInput = False
                    Exit Function
               End With
          End If
     Next
     Return True
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top