function We need a row selection operation in the Data window. If a user chooses a row in order to modify the data or see more detailed content, and in other cases the user may want to delete or modify multiple rows at the same time, we need to have the ability to enable the user to select multiple rows at the same time in a data window. This is fairly easy to do in PowerBuilder, but it is cumbersome to repeat programming in each window if there is no standard function in the ancestor of a data window to handle this. Let's take a look at the different ways to make a row selection. • All rows are not highlighted. Typically, the data window does not highlight any rows. This is appropriate for a list of data that only allows the user to scroll and view, or for data windows of those single lines. • Single-line Select single line selection means that users can only select one row at a time to perform some actions, such as deleting or displaying details in the master-detail list, which is useful. Here is the code that implements the Single-line selection feature: Event:rowfocuschangedif GetRow () > 0 then SelectRow (0, FALSE) selectrow (GetRow (), TRUE) End If multiple-line automatic selection Multi-line Automatic selection performance: When the user clicks on an unlit row, the row will brighten, otherwise, the user clicks on a highlighted line, the row will not be highlighted. To achieve this, add the following code 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 simplified to the following line of code: if GetRow () > 0 t Hen SelectRow (GetRow (), not isselected (GetRow ())) shift, control, or control+shift+ mouse using a Windows File Manager or other Windows program, You can choose between this keyboard and mouse combination using SHIFT, control, or Control+shift. PowerBuilder does not provide this capability in the data window, we must implement it ourselves. The combination function that we should implement is to create such a feature that the data window must record the current starting row. We declare such an instance variable: protected Long Il_ Anchor _Row when the user clicks the mouse or takes a keyboard action, we test whether the user has pressed the shift or control key at the same time by using the KeyDown () function, checking for keyshift! and keycontrol!, and recording the start line if such a key is pressed. To write a row selection function to make this behavior work when a user clicks or plays a keyboard, we must call our own row selection function in the clicked event and a custom user event that maps to the PBM _ Dwnkey event. In this way, the selection behavior occurs regardless of whether the user clicks the mouse or hits the keyboard. We can also put this feature into the Rowfocuschanged event. To make this line selection function reusable, here we create two functions. A function sets the type of selection behavior we want, and the other one actually executes 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 contain some of the following values. Possible selection behavior value behavior 0 do not allow selection behavior 1 only allow one row to select 2 Automatic multiple-line selection 3 allow mouse and keyboard combinations to select 99 do not allow selection, turn the mouse into a hand if you are using a protection variable or a private variable, this means that programs other than this object cannot be accessed, so you must The order member establishes a function to assign values to these variables and to obtain the values of those variables. In addition, some functions are required to execute the process based on the variable. Functions: Uf_setselect (Select_behavior) The first function we want to write will allow the programmer to set the selection behavior. Functions: Public integer uf_ setselect (integer ai_ select_ behavior)/* This function sets the selection behavior value of the data window The following is a valid selection behavior value */choose case Ai_select_beha Vior case 0, 1, 2, 3, ii_ select_ behavior = ai_ select_//At least one line will be selected if behavior ai_ select_ = 1 behavior then uf_ Ess_ Select (GetRow (), "keyboard") End If if ai_ select_ behavior = on then Setrowfocusindicator (hand!) Else Setrowfocusi Ndicator (off!)End If return 0 case ELSE return-1 end CHOOSE Once the selection type is set, all rows must be processed. We put this part of the code into a function called Uf_ processselect. This function handles the selection behavior. We need to tell the line that the function is to process and whether the request was made by the mouse or the keyboard. Here's the function code: function: Uf_ processselect (Long Al_ Row, string As_ input_ type) long L_ row Boolean b_ reset_ anchor Boolean b_ Keybo ARD, b_ mouse//mouse action or keyboard action? If Upper (left (as_input_type,1)) = "K" then b_ keyboard = TrueElse B_ mouse = TrueEnd if/* Confirm that the mouse point is on the record of the data window */if al_ row 1 Then return-1/* whether to determine the starting row */b_ reset_ anchor = Truesetredraw (FALSE) CHOOSE case ii_ select_ behavior case 0, 99//No Case 1 Single-row check SelectRow (0,false) SelectRow (al_row,true) Case 2/Multiple lines Select if B_ mouse then SelectRow (Al_ row, not isselected (Al_ Row)) End If Case 3 if KeyDown (keyshift!) and KeyDown (keycontrol!) Then if Il_anchor_row, Al_row then for l_ row = Il_ A Nchor_ 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_ row,true) NEXT else for l_ row = Il_ Anch Or_ row to Al_ row This.selectrow (l_row,true) NEXT End If b_ reset_ anchor = FALSE ElseIf Keydown (keycontrol!) then Select Row (Al_row, not isselected (Al_row)) Else SelectRow (0,false) selectrow (Al_ row,true) End IfEnd Choosesetredraw (TRUE) if B_ reset_ Anchor then il_ anchor_ row = Al_ Rowreturn 0 Now, to perform a row selection, simply invoke the Uf_processselect () function. This function is called when the user clicks the mouse in a data window or presses the UP and DOWN ARROW keys. There is also code to capture the home and end keys. The following is the code for the We_keydown user event map 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 (keyend!) and rowcount () > 0 then uf_ Processselect (RowCount (), "keyboard") End If finally, we need the CLI CKed event Add: Uf_ processselect (Getclickedrow (), "Mouse") writing such a line-selection function in this ancestor function is only a simple example, and I believe that readers will be inspired to write more functions, To expand the basic functions of the Data window.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.