SelLength, SelStart, SelText

These three properties control selected text in those controls where textual entry is permitted: text boxes, edit boxes, spinners and combo boxes. You can figure out what the user highlighted or you can highlight text programmatically.

Usage

oObject.SelLength = nNumCharsHighlighted
nNumCharsHighlighted = oObject.SelLength
oObject.SelStart = nFirstCharHighlighted
nFirstCharHighlighted = oObject.SelStart
oObject.SelText = cCharsHighlighted
cCharsHighlighted = oObject.SelText
When no text is highlighted, SelStart indicates the position of the cursor in the text. In that case, SelLength is 0. Otherwise, SelStart is the start of the highlighted text and SelLength is the number of highlighted characters.You can change the position of the highlight by manipulating SelStart and SelLength. Even cooler, you can actually change the text itself by manipulating SelText. You can put any text you want right into the control (except that, with spinners, it has to be digits). This solves one of the trickiest problems we had with FoxPro 2.x—getting our hands on selected text and modifying it in some way.Except for spinners, the selection is maintained even when that control isn't the active control. When you return to the control (by tabbing), the same text is highlighted.

Spinners act really weird. If you type into a spinner, the digits aren't all the way against the arrows. If you highlight some of the text you've typed while you're still there, it becomes SelText, but as soon as you tab out of the spinner, the text you typed moves to the right and SelText changes to the characters now in the position specified by SelStart and SelLength.


Finally, combo boxes only let you fiddle with these properties when their Style is 0 for combo. If you use the drop-down style (2), the entire length of the current item is highlighted regardless of these properties.

It's okay that you can't change these properties for combos set up as drop-down lists. What's not okay is that they don't tell you anything in that case. They should provide the information about the currently selected item.


Example

* Change the current selection of a control
* to lowercase. Assume we're in a method of
* the control.  
This.SelText = LOWER(This.SelText)
 
* Highlight the 5th through 10th characters
* of edit box EDIT1 on the current form
ThisForm.Edit1.SelStart = 5
ThisForm.Edit1.SelLength = 6

See Also

ComboBox, EditBox, HideSelection, Spinner, TextBox


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .