Sunday, September 12, 2004

VFP ListBoxes: Right-Click with Multiple Selections

Something to be aware of if you like to use right-clicks with list boxes in Visual FoxPro.
 
VFP doesn't act like other applications in the way it responds to right-clicks in list boxes.
 
If you turn multi-select on, select multiple items and then right-click on one, only the item right under the mouse will remain selected.
 
This is unfortunate because it means you can't do a right-click action on multiple selections in a list box.
 
Solution?
 
Use the MS Forms List ActiveX control instead. The difference is that you need to use the MouseUp method (since it doesn't have the RightClick method)
 
The control is Forms.Listbox.1 so you can do a createobject("Forms.listbox.1")
 
Subclass this control into your main foundation class and you can create your own RightClick method so none of your other code needs to change.
 
Other changes?
The Listbox uses a Font object (instead of FontName, FontSize). So either get used to using the Font object (Font.Name, Font.Size, etc) or create your own FontName and FontSize properties with access and assign methods.
 
PROCEDURE FontName_Assign (tcFont)
 
THIS.FontName = tcFont
THIS.Font.Name = tcFont

No comments: