Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I trap right/double click of item in ListView
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01185259
Message ID:
01185736
Views:
15
The right click should do an 'item' select. The item in the list will be hihlighted - so you would - in that case have the item/node object properties (key, text, index) available by just examing the node. The just assure it is selected either in code:
myForm.myListView.SelectedItem.Selected=.t.
Or in the ListView's ITemClick Method:
PROCEDURE itemclick(loItem)
IF loItem.key#this.tag
   IF this.tag=[x]
      this.HideSelection=.f.
   ENDIF 
   loItem.Selected=.t.
   loItem.EnsureVisible
ENDIF 
ENDPROC
In this case, you would not need the hittest. You could just take the "node" info and run a GUI or a popup menu.
The X/Y coords in hittest are not pixel x/y's from the mouse pointer - they are converted to twips using this code:
public unLTVX,unLTVY && Twip metric scalars
DeclareWindowsAPIFunctions() && Run these first to assign unLTVX and unLTVY 
GetDisplayMetrics()

PROCEDURE DeclareWindowsAPIFunctions()
declare integer GetActiveWindow in WIN32API
declare integer GetDC in WIN32API integer iHDC
declare integer GetDeviceCaps in WIN32API integer iHDC,integer iIndex
ENDPROC &&R6_PSA_DeclareWindowsAPIFunctions

procedure GetDisplayMetrics()
local liHwnd,liHDC,liPixelsPerInchX,liPixelsPerInchY
liHwnd=GetActiveWindow()
liHDC=GetDC(liHwnd)
* Pixels per Inch
liPixelsPerInchX=GetDeviceCaps(liHDC,88)
liPixelsPerInchY=GetDeviceCaps(liHDC,90)
* Twips per pixel and store
unLTVX=1440/liPixelsPerInchX &&The twips scaling are now in the public 
unLTVY=1440/liPixelsPerInchY && vars, unLTVX and unLTVY
Now that you have your scalars, you can fire a hittest in your mousemove:
PROCEDURE MouseMove(button, shift, x, y)
* Implements a scanning preview of the the
* of the ListView nodes when the chkHotTracker is true.
*(You may not want to fire it all the time
IF thisform.chkHotTracker.Value=1
   oNode=this.HitTest(X*unLTVX,Y*unltvY) && See the scalars!
   IF type('oNode.text')==[C] && A hit!
      this.ItemClick(oNode) && Run the item click(above)
   ENDIF &&type('oNode.text')==[C]
ENDIF &&.chkHotTracker.Value=1
ENDPROC &&MouseMove
If the goal is to fire a popup - you will have to define it depending on the node you hit.

You can make a right mouse down select the Listview item - and then use the rightmouse up to fire the procedure to DEFINE the popup - sometimes you may want information form the list view or it's underlying table to build your popu[. I typically assign a key (part number - sys() value) that I can use to quickly point to a record in a table.

In the mouseup of your list view you might have code like this to fire a popup menu:
PROCEDURE mouseup (button, shift, x, y)
if button=2
   external array aMSL && MultiSelectList container filled in another proc
   this.hideselection=.f.
   llMultiSelected=TestForMulitiSelects(thisform,this)
   oTagNameNode;
=this.ListItems(this.selecteditem.key).ListSubitems(this.COLUMNHEADERS([myListCol]).SubItemIndex)
oTagValueNode;
=this.ListItems(this.selecteditem.key).ListSubitems(this.COLUMNHEADERS([OtherCol]).SubItemIndex)  
   cTagName=iif(llMultiSelected,[Multiple Items Selected],oTagNameNode.text)
   cTagKey=iif(llMultiSelected,[_MULTIBLE],this.selecteditem.key)
   Define_ItemPopUpMenu(thisform,cTagName) && See Below
   * Now, open the popup - see below after definition
OpenPopUP_Menu_Item(y/10,x,thisform,this.object,cTagName,cTagKey,llMultiSelected)
   ulRightButtonDown=.F. && A control for multiple right mouses
                         && The menu opens to select - then loses
                         && Then opens to paste
endif
endproc
Define the ItemPopUpMenu:
PROCEDURE Define_ItemPopUpMenu(oform,lcTagName) 
DEFINE POPUP pop_Item MARGIN RELATIVE shortcut TITLE lcTagName COLOR SCHEME 4
ENDPROC &&Define_ItemPopUpMenu(oform,lcTagName)
And the ItemPopUpMenu definition might look like this:
PROCEDURE OpenPopUP_Menu_Item(nRow,nCol,oform,oListView,lcTagName,lcTagKey,lMulti)
push key clear
*Note variables beginning with "U" are public vars
DEFINE BAR 1 OF pop_Item PROMPT 'Insert '+ucCopy_Key+' \<before '+lcTagKey key ALT+B, "ALT+B" ;
       skip for ucActionStatus#[MOVE] or lcTagKey=[_MULTIBLE]
DEFINE BAR 2 OF pop_Item PROMPT '\<Insert '+ucCopy_Key+' after '+lcTagKey key ALT+I, "ALT+I" ;
       skip for ucActionStatus#[MOVE] or lcTagKey=[_MULTIBLE]

ON SELECTION BAR 1 of pop_Item DO pop_InsertItem with oform,lcTagKey,.F. && Before
ON SELECTION BAR 2 of pop_Item do pop_InsertItem with oform,lcTagKey,.T. && AFter
ACTIVATE popup pop_Item at nRow,nCol
DEACTIVATE POPUP pop_Item
pop key
ENDPROC &&OpenPopUP_Menu_Item(nRow,nCol,oform,oT2CF,lcTagName,lcTagKey,lMulti)
If you want more infor ion Hittest - Download RIO.ZIP on the UT. Don't pay attention to the VFP 7 message (disable it in the source code if you want). Use messageboxes to help you understand what is happening. And - if you can - build a simple model with a test form and ListView and the drive it from COMMAND WINDOW - it sure saves time that re-runing a PRG will cost - just to find you misspelled a reference or skipped a comma!

BUT - you should not need a Hittest for a right mouse event on the ListView - However - if in the end - you want to develop SEXy (Syntactically Explicit Xbase) apps - check out RIO's "Hot Navaigator").

You are going to have a lot of fun doin this. Are you implementing an imagelist? RIO has an idea for that too.
Imagination is more important than knowledge
Previous
Reply
Map
View

Click here to load this message in the networking platform