Write line selection functions

zhaozj2021-02-17  77

We need to perform row selection operations in the data window, such as selecting a row in order to modify data or see more detailed content; in other cases, users may have to delete or modify multi-line, then we need There is a multi-line feature that enables users to select multiple lines simultaneously in a data window. This is quite easy to do in PowerBuilder, however, if there is no standard function in a data window ancestor, it is very troublesome in each window.

Let's take a look at the different methods for performing line selection.

· All rows do not brighten usually the data window does not highlight any rows. This is suitable for data lists that only allow users to scroll and view them or those single-line data windows.

· The single line choice of single line means that the user can only select one line at the same time to perform some actions, such as deleting or displaying more information in the list of primary roughness, which is very useful. Below is the code that implements a single line selection function:

Event: RowFocuschangeDif Gtrow ()> 0 THEN

SELECTROW (0, FALSE)

SELECTROW (GetRow (), true) End if · Multi-line automatic selection Multi-line automatic selection performance is: When the user clicks on a unlighted row, the line will shift; contrary, the user clicks on a plus line, The line will not be high. In order to achieve the above functions, the following code is added to the RowFocusChanged event:

Event: RowFocuschangeDObject: Any DataWindowif GetRow ()> 0 THEN

IF isselected (getRow ()) THEN

SELECTROW (GetRow (), FALSE

Else

SELECTROW (GetRow (), TRUE

End IFEND IF or simplifies the following line of code:

If GetRow ()> 0 Then SELECTROW (GetRow (), NOT ISSELECTED (GetRow ())) · SHIFT, Control or Control Shift mouse Using Windows file manager or other Windows program, you can use Shift, Control or Control Shift This keyboard is selected from the combination of mice. Powerbuilder does not provide such an capability in the data window, we must implement itself.

The combined function we should implement is:

To establish such functions, the data window must record the current starting line. We declare such an instance variable:

Protected long il_ anchor _ row When the user clicks on the mouse or performs the keyboard operation, we have to test the user at the same time, and the method is to use the keydown () function, check whether there is Keyshift! and KeyControl !, if Such a key is pressed to record the starting line.

Write line selection functions

In order to make the above behavior when the user clicks on the mouse or performs a keyboard operation, we must call our own row selection function in a custom user event that maps to the PBM_ DWNKEY event. In this way, the selection behavior occurs regardless of whether the user is clicking on a mouse or hitting a keyboard. We can also put this feature into the ROWFOCUSCHANGED event.

In order to make this line selection function reuse, we build two functions. A function settings we want to choose the behavior type, and another truly execute the selection behavior. First we use an instance variable to set the value of the selection behavior:

Protected Integer II _ Select_ Behavior This variable will be stored in this variable.

Possible selection behavior

Value behavior

0 Do not allow selection behavior

1 only one line is selected

2 Automatically implement multi-line selection

3 Allows the use of mouse and keyboard combination

99 Do not allow the choice, turn the mouse into a hand

If you are using a protective variable or a private variable, this means that the program other than this object cannot be accessed, so it must be assigned to other programmers to assign and obtain these variable values.

In addition, some functions need to perform the process based on this variable.

Function: uf_setselect (select_behavior) We want to write the first function to allow programmers to set up the selection behavior.

Function: public integer uf_ setselect (Integer ai_ select_ behavior) / * This function sets the selection behavior value of the data window listed as a valid selection behavior value * / choose case ai_select_behavior case 0, 1, 2, 3, 99

II_ select_ behavior = ai_ select_ behavior

// At least one line will be selected

IF ai_ select_ behavior = 1 THEN

UF_ process_ select (getRow (), "keyboard")

END IF

IF AI_ SELECT_BEHAVIOR = 99 THEN

SetrowFocusindicator (Hand!)

Else

SetrowFocusindicator (OFF!)

END IF

Return 0 Case Else

Return -1

End chaoose

Once the selected type is set, all rows must be processed. We put this part of the code in a function called UF_ ProcessSelectSelect. This function handles selection behavior. We need to tell the function to process and the request is sent by the mouse or the keyboard. Below is the function code:

Function: uf_ processselect (long al_ row, string as_ infut_ type)

Long L_ row

Boolean B_RESET_ Anchor

Boolean B_ Keyboard, B_ Mouse

/ / Mouse action or keyboard action?

IF Upper (AS_INPUT_TYPE, 1) = "k" Then

B_ Keyboard = Trueelse

B_ mouse = trueend if / * confirms that the mouse point is recorded on the data window * / if Al_ ROW <1 Then Return -1 / * Does whether to determine the starting line * / b_ reset_ anchor = trueSetredRaw (false) choose case II_ SELECT_ Behavior Case 0, 99 // No case 1 // single line selection

SELECTROW (0, FALSE)

Selectrow (al_row, true) case 2 // multi-line selection

IF b_ mouse thein

SELECTROW (Al_ Row, not isselected)

END IF CASE 3

IF keydown (Keyshift!) and keydown (KeyControl!) THEN

IF IL_ANACHOR_ROW> Al_Row Then

For L_ Row = IL_ anchor_ row to al_ row step -1

this.selectrow (L_Row, True)

NEXT

Else

For L_ Row = IL_ anchor_ row to al_ row

this.selectrow (L_Row, True)

NEXT

End if elseif keydown (Keyshift!) THEN

SELECTROW (0, FALSE)

IF IL_ Anchor_ Row> Al_ Row Then

For L_ Row = IL_ anchor_ row to al_ row step -1

this.selectrow (l_ rot, true)

NEXT

Else

For L_ Row = IL_ anchor_ row to al_ row

this.selectrow (L_Row, True)

NEXT

END IF

B_RESET_ anchor = false

Elseif KeyDown (KeyControl!) Thenselectrow (al_row, not isselected) ELSE

SELECTROW (0, FALSE)

SELECTROW (Al_ Row, True) End & '' This function is called when the user clicks the mouse in a data window or pressing the arrow button. There is also a code that captures the HOME and END keys. Below is the code that the WE_KEYDOWN user event is mapped to the PBM_DWNKEY event:

Event: WE_ KeyDown (PBM_DWNKEY) Object: Any DataWindow

IF keydown (keydownArrow!) and getrow () <> rowcount () THEN

UF_ processselect (getRow () 1, "keyboard") Elseif Keydown (KeyuParrow!) and getrow () <> 1 THEN

UF_ processselect (GetRow () - 1, "keyboard") elseif keydown (keyhome!) And rowcount ()> 0 THEN

Uf_ processselect (1, "keyboard") elseif keydown (keynd!) and rowcount ()> 0 THEN

UF_ ProcessSelect (RowCount (), "Keyboard") endiff Finally, we need to join in the Clicked event:

UF_ processselect (getClickedRow (), "mouse") Writing such a line selected in this ancestor is just as a simple instance, I believe that the reader must be inspired, writing more functions, to expand the data window basic skills.

转载请注明原文地址:https://www.9cbs.com/read-31080.html

New Post(0)