ListView and TreeView controls events changed

PowerBuilder 7 and later use Microsoft ListView and TreeView controls. As a result, you might see some changes in behavior that require you to remap some events. When you perform mouse actions, some events do not fire, and some fire in a different order from previous releases.

TreeView

In PowerBuilder 7 and later, the pbm_rbuttonup event does not fire, but is immediately followed by a pbm_tvnrclicked event (the stock RightClicked! event for a TreeView). Therefore, you can copy any code from pbm_rbuttonup to RightClicked! or have the RightClicked! event trigger whatever code exists in the pbm_rbuttonup. In PowerBuilder 6 both pbm_rbuttonup and pbm_tvnrclicked fire.

Additionally, in PowerBuilder 7 and later, using the right mouse button to select a previously unselected TreeView item causes the previous TreeView item to regain focus when the button is released. In PowerBuilder 6, using the right mouse button to select a TreeView item causes it to become permanently selected. To duplicate this behavior in PowerBuilder 7 and later, place the line of code this.SelectItem(handle) in the RightClicked! event of the TreeView before triggering (or otherwise executing) code from the pbm_rbuttonup event.

In PowerBuilder 7 and later, the pbm_tvnrdoubleclick event (the stock RightDoubleClicked! event) does not fire but is immediately preceded by a pbm_rbuttondblclk event. Therefore, you can copy any code from the RightDoubleClicked! event to the pbm_rbuttondblclk event or have the pbm_rbuttondblclk event trigger existing code in the RightDoubleClicked! event. Both events fire in PowerBuilder 6.

ListView

In PowerBuilder 7 and later, the pbm_rbuttonup event does not fire if you use right-click on a specific ListView item, but it does fire if you right-click in the white area of the ListView where there are no items. A new event, pbm_contextmenu, always fires when the right mouse button is released. Table 3 shows when events are fired in PowerBuilder 7 and later.

Location

Action Events fired

On an item in a ListView

Press right mouse button

pbm_rbuttondown

Release right mouse button

pbm_lvnrclicked (the stock RightClicked! event)

pbm_contextmenu

 

On an empty area of the ListView

Press right mouse button

pbm_rbuttondown pbm_lvnrclicked (the stock RightClicked!event)

pbm_contextmenu

Release right mouse button

pbm_rbuttonup

pbm_contextmenu

 

You should place code that should be executed when an item is actually selected by the right mouse button in the pbm_contextmenu event. This is how PFC ListView objects work in PowerBuilder 7 and later. The code that you want executed when the right mouse button is released on the white area of the ListView should remain in the pbm_rbuttonup event. Because pbm_contextmenu is called twice when you right-click in the white area, you should put code in the RightClicked event to retain the index of the item that was selected. If no item is selected, then the index value will be zero and you should use that as a test in the pbm_contextmenu code to decide whether that code should be executed.

The following example assumes that you have declared a private instance variable of a TreeView standard class user object called ii_item. This statement is in the Clicked! event script:

ii_item = index

The pbm_rbuttonup event script should contain code to be executed when the right mouse button is released after being pressed in the ListView but not on an item in that ListView.

The pbm_contextmenu event script should contain code like the following:

IF ii_item > 0 THEN 
// code to be executed when the right mouse 
// button is released after being pressed on an 
// item in the ListView 
END IF

The pfc_u_lv and pfc_uv_lvs objects have been modified to use pbm_contextmenu instead of pbm_rbuttonup.

NOTE: The PowerBuilder and InfoMaker Release Bulletins, New Features Guides were used as sources for this document.