SelectText

Selects text in an edit control.

To select text in

Use

A DataWindow when the DataWindow does not have the RichTextEdit presentation style, or a RichText edit-style column in such a DataWindow

Syntax 1

A DataWindow whose object has the RichTextEdit presentation style (PowerBuilder only)

Syntax 2


Syntax 1 For DataWindows with standard edit styles

Description

Selects text in an editable control. You specify where the selection begins and how many characters to select.

This method works for DataWindows with standard edit styles (non-RichTextEdit style), or columns which have the RichText edit style in such DataWindows.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control


Syntax

PowerBuilder

long dwcontrol.SelectText ( long start, long length )

Argument

Description

dwcontrol

A reference to a DataWindow control.

start

A numeric value specifying the position at which you want to start the selection.

length

A numeric value specifying the number of characters you want to select. If length is 0, no text is selected but SelectText moves the insertion point to the location specified in start.


Return value

Returns the number of characters selected. If an error occurs, SelectText returns -1.

If any argument's value is null, in PowerBuilder and JavaScript the method returns null.

Usage

If the control does not have the focus when you call SelectText, then the text is not highlighted until the control has focus. To set focus on the control so that the selected text is highlighted, call the SetFocus function.

To select text in a DataWindow with the RichTextEdit presentation style, use Syntax 2.

PowerBuilder environment

For use with other PowerBuilder controls, see the section called “SelectText” in PowerScript Reference.

Backward selection in a RichText edit-style column

Both the new control and the old control cannot correctly handle the backward selection in a RichText edit-style column via the SelectText (although forward selection is well supported).

When backward selecting a string (which means length is a negative number) in a RichText edit-style column, the old control will only select the character before the last one and return 1. The new control will select two more extra characters and returns the number of the actual selected characters. For example, in the following statement, the old control selects the 9th characters and returns 1; while the new control will select 7 characters from 4th to 10th, and returns 7.

dw_1.selectText(10,-5)

Examples

This statement sets the insertion point at the end of the text in the DataWindow edit control:

dw_1.SelectText(dw_1.GetText(), 0)

This statement selects the entire contents of the DataWindow edit control:

dw_1.SelectText(1, Len(dw_1.GetText()))

The rest of these examples assume the DataWindow edit control contains Boston Street.

The following statement selects the string ost and returns 3:

dw_1.SelectText(2, 3)

The next statement selects the string oston Street and returns 12:

dw_1.SelectText(2, Len(dw_1.GetText()))

These statements select the string Bos, returns 3, and sets the focus to the DataWindow control so that Bos is highlighted:

dw_1.SelectText(1, 3)
dw_1.SetFocus()

See also

Position

SelectedText

TextLine

Syntax 2 For RichTextEdit DataWindows

Description

Selects text beginning and ending at a line and character position in a RichText DataWindow.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control


Syntax

PowerBuilder

long rtedwcontrol.SelectText ( long fromline, long fromchar, long toline, long tochar { band band } )

Argument

Description

rtedwcontrol

A reference to the DataWindow control in which you want to select text. The DataWindow object in the DataWindow control must have the RichText presentation style.

fromline

A value specifying the line number where the selection starts.

fromchar

A value specifying the number in the line of the first character in the selection.

toline

A value specifying the line number where the selection ends. To specify an insertion point, set toline and tochar to 0.

tochar

A value specifying the number in the line of the character before which the selection ends.

band (optional)

A value of the Band enumerated datatype specifying the band in which to make the selection. Values are:

  • Detail!

  • Header!

  • Footer!

The default is the band that contains the insertion point.


Return value

Returns the number of characters selected. A carriage return with a line feed counts as a single character. If an error occurs SelectText returns -1. If any argument's value is null, it returns null.

Usage

The insertion point is at the "to" end of the selection -- that is, the position specified by toline and tochar. If toline and tochar are before fromline and fromchar, then the insertion point is at the beginning of the selection.

You cannot specify 0 for a character position when making a selection.

You cannot always use the values returned by Position to make a selection. Position can return a character position of 0 when the insertion point is at the beginning of a line.

To select an entire line, set the insertion point and call SelectTextLine. To select the rest of a line, set the insertion point and call SelectText with a character position greater than the line length.

PowerBuilder environment

For use with other PowerBuilder controls, see the section called “SelectText” in PowerScript Reference.

Examples

SelectText is used in the same way for RichTextEdit controls and RichText DataWindow controls. For sample code, see the examples for the RichTextEdit control in the PowerScript Reference.

See also

SelectedText

SelectTextAll

SelectTextLine

SelectTextWord