A while ago, I posted a bug report about using Contextual Menus when  
there are multiple items selected in a listbox.

http://www.realsoftware.com/feedback/viewreport.php?reportid=lvdlmdas

The problem is that if you have several items selected, when you  
right-click on the list (CTRL-click on Mac), the selection changes  
and you end up with only one item selected (where you clicked). The  
suggestion was to make a routine in the MouseDown event to handle the  
situations where multiple items were selected. Although I am grateful  
for the workaround, my fear is that with two ways of showing a  
Contextual menu, the old way will be eventually depreciated. I also  
found it rather clunky to deal with things differently depending on  
the number of selected items (and having to remember), since I really  
like using the new events (ConstructContextualMenu and  
ContextualMenuAction). Also, the workaround still had the problem of  
the selection changing, albeit after the MouseDown event fired.  
Anyway, I found another workaround which seems to work better, and  
lets you use the ConstructContextualMenu and ContextualMenuAction  
events.

1. Create a subclass of the ListBox class, name it something like  
ListBoxFix.
2. Add two properties:
     Private SelItems() as Integer
     Private ShowingContextMenu as Boolean
3. Add two event definitions:
     Change()
     MouseDown(x as Integer, y as Integer) as Boolean
4. Add the following code:
     To the Change() Event:
         dim i as integer
         if ShowingContextMenu then
           for i = 0 to me.LastIndex
             if SelItems.IndexOf(i)>-1 then me.selected(i) = true
           next i
         else
           redim SelItems(-1)
           for i = 0 to me.LastIndex
             if me.Selected(i) then SelItems.Append(i)
           next i
         end if
         Change()

5. Add the following code to the MouseDown event:
       ShowingContextMenu = IsContextualClick
       return MouseDown(x,y)

Now change your existing ListBox super to ListBoxFix. Very cool it  
works now!


Greg - 2007r1 on Mac G5



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to