Listbox use and too many options?

Hi All,

I’m stumped about the use of the various events with the standard listbox. Specifically how some events interact - or even supersede - others.

Here’s what I need to be able to accomplish to get this right:

1 - Normal, single row selection and population of a secondary list “if” the cell tag on the x,0 cell of the selected row is of type “1” “and” we’re not expanding “and” we’re not dragging “and” we’re not multi-selecting.
2 - Normal Expansion of a folder
3 - Support for extended / multiple selections
4 - Contextual menu support for both populated rows and blank areas
5 - DragReorder drag and drop of selected rows (single or multiple) into a folder

Basically (no pun intended), I can get 1, 2 & 4, or 1, 2 & 3, or 1, 2 & 5 working, but I’ve been unable to satisfy all 5 at the same time and that’s my dilemma. I need to satisfy all 5 situations.

I know that these can be done as I’ve seen it accomplished in things like the Feedback app, but there’s no logic that I’ve been able to discern from the OLR or books. Thom, Norman?

For contextual menu check in MouseDown and throw up the menu if IsContextalClick is true using menuitem.popup instead of relying on the contextual menu events

That’s how I got what I did get working, well, working.

I placed checks for Contextual menu, expansion (X < 22), and Shift or Cmd/Ctrl (extended selection) into the MouseDown and returned False if they were met. Otherwise I returned True and dealt with the rest in the MouseUp. However, neither MouseDrag nor DragReorderRow events fire in those circumstances. That’s what I can’t seem to sort out.

I have code where i do ALL of that at the same time. The ONLY time I return TRUE in Mouse down is when I handle the contextual menu there myself. I do that so a contextual click does not change the selection.

I write methods to construct the menu and handle the return value that I put into the contextual menu events or can be called from mousedown when I use menuItem.popup there

How do you differentiate between a drag reorder or a Drag to drop?

Once you set DragReorder to true you can’t stop teh drag only not accept the drop… but you can disallow the regular dragging of a row by returning false in dragRow… But I do something else. In Drag row i create my own drag item so I can create a semi-transparent drag picture to show what is being dragged.

BTW sometime when i want to either drag-reorder or drag and drop teh same row(s) i will do the above to allow both at the same time using that drag-item so I don’t have have 2 drag visual indicators… In that cause I use mouse over and invalidateRow and CellBackground paint to indicate where it is legal to drop a drag-reorder. (Change teh background of the row below dragitem to either red or green and an draw an arrow to show above or below.)

[quote=25597:@Karen Atkocius]I have code where i do ALL of that at the same time. The ONLY time I return TRUE in Mouse down is when I handle the contextual menu there myself. I do that so a contextual click does not change the selection.

I write methods to construct the menu and handle the return value that I put into the contextual menu events or can be called from mousedown when I use menuItem.popup there

How do you differentiate between a drag reorder or a Drag to drop?

Once you set DragReorder to true you can’t stop teh drag only not accept the drop… but you can disallow the regular dragging of a row by returning false in dragRow… But I do something else. In Drag row i create my own drag item so I can create a semi-transparent drag picture to show what is being dragged instead of just an outline of the row(s).

BTW sometime when i want to either drag-reorder or drag and drop the same row(s) i will do the above to allow both at the same time using that drag-item so I don’t have have 2 drag visual indicators… In that case I use MouseOver and invalidate the row it’s over and use CellBackgroundPaint to indicate where it is legal to drop a drag-reorder. (Change the background of the row below the dragitem to either red or green and an draw an arrow to show above or below.)[/quote]

Your hint about using the MouseDown for as much as possible has made a big difference. The only thing that I still can’t sort out is how to process the Contextual Menu when multiple items are selected. Now, anytime I ContextualClick on the listbox, the selections are dropped and only the row under the mouse is selected.

I handle the ContextualMenuClick as the first case in the MouseDown.

Thanks for the input on this.

Can you return true from CellClick in this case to retain the selection? Curious.

Unfortunately, CellClick isn’t called any more when you use MouseDown / MouseUp nor does it return a boolean.

Why I asked, from the LR… “CellClick returns a Boolean. Returning True means that the event will not be processed further (i.e., editable cells won’t be editable and ListBox selection won’t change).” But it sounds like you’re already returning true from MouseDown and bypassing that.

In MouseDown, process the contextual menu and return True.

@Tim Hare - so I need to manage the CM directly instead of allowing the ContextualMenuAction event handle it as it does when I return False? I’ll give that a try.

Thats an old one, see <https://xojo.com/issue/1705>

Correct, that was Karen’s original suggestion.

Note: In a subclass, you can call the ConstructContextualMenu and ContextualMenuAction events from the MouseDown event, if you want to leave your code in them. That is how I handle it.

[quote=25754:@Tim Jones]Your hint about using the MouseDown for as much as possible has made a big difference. The only thing that I still can’t sort out is how to process the Contextual Menu when multiple items are selected. Now, anytime I ContextualClick on the listbox, the selections are dropped and only the row under the mouse is selected.

I handle the ContextualMenuClick as the first case in the MouseDown.
[/quote]

If you do something like this In MouseDown:

If IsContextextualClick Then
   Dim Base as menuItem
   BuildMyContextual(Base,X,Y)
   Dim HiteItem as MenuItem = Base.popup
   If HitItem <> NIL Then HandleMenuSelection(HitItem, X,Y)
   RETURN TRUE
End if

You won’t change the selection

Thanks Tim and Karen. As Tim mentioned (and I misunderstood from Karen’s earlier reply), I moved the menu creation and handler into the MouseDown event and all of the selected entries stay selected when I Contextual click.

Thanks for helping to sort this. Hopefully, I’ll have time to submit these steps to the Language Ref and User Guide to clarify this process for others.

@Maximilian - I see that Norman has recently reviewed that report.