NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

UpDownBase.Select

Selects a range of text in the up-down control.

[Visual Basic]
Public Sub Select( _
   ByVal start As Integer, _
   ByVal length As Integer _
)
[C#]
public void Select(
   int start,
   int length
);
[C++]
public: void Select(
   int start,
   int length
);
[JScript]
public function Select(
   start : int,
   length : int
);

Parameters

start
The position of the first character to be selected.
length
The total number of characters to be selected.

Remarks

The Select method can be used when the up-down control gets focus, or when the Text propertry fails data validation. When adding the validation code for the ValidateEditText method in a derived class, call the Select method when validation fails.

Example [Visual Basic]

The following example uses the derived class, NumericUpDown. This code assumes you have a NumericUpDown control and a Button instantiated on a form. On the System.WinForms.Control.Click of the button, the point size of text in the NumericUpDown control increases. This will prompt the control to adjust its PreferredHeight property so all of the text is visible in the control. As the user types in a new value in the NumericUpDown control, the text is converted to a numeric value from a string value and validated to be between the System.WinForms.UpDownBase.Minimum and System.WinForms.UpDownBase.Maximum values. If the value is not valid, the Select method will select the text so the user can enter new a new value.

[Visual Basic]

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs)
   ' If the entered value is greater than Minimum or Maximum, 
   ' select the text and open a message box.
   If CInt(NumericUpDown1.Text) > NumericUpDown1.Maximum Or _
     CInt(NumericUpDown1.Text) < NumericUpDown1.Minimum Then
      NumericUpDown1.Select 0, Len(NumericUpDown1.Text)
      MsgBox "The value entered was not between the Minimum and Maximum allowable values." _
       & vbCrLf & "Please re-enter.", , "Invalid Value"
   End If
    
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs)
   Dim varPrefHeight1 As Integer
   Dim varPrefHeight2 As Integer

   ' Capture the PreferredHeight in variables before and after 
   ' the Font is changed, display the results in a message box.
   varPrefHeight1 = NumericUpDown1.PreferredHeight
   Set NumericUpDown1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, _
     System.Drawing.FontSize.Points, System.Drawing.FontWeight.Bold, False, False, _
     False, System.Drawing.CharacterSet.Default, 0)
   varPrefHeight2 = NumericUpDown1.PreferredHeight
    
   MsgBox "Before Font Change: " & varPrefHeight1 & "After Font Change: " _
     & varPrefHeight2, , "Preferred Height"

End Sub

See Also

UpDownBase Class | UpDownBase Members | System.WinForms Namespace | ValidateEditText