How to prevent a user from dropping an expandable row into another expanded expandable row?

In a Desktoplistbox I want the user to be able to reorder only the expandable rows. And I’m using this code in the Mousedown Event:

If Me.RowExpandableAt(Row) Then Me.AllowRowReordering = True
If Me.RowExpandableAt(Row) = False Then Me.AllowRowReordering = False

This works perfectly well. But it will not prevent the user from dropping an expandable row within another expandable row if the destination row is expanded.
I guess the easy (or maybe right) solution would be to ask the user to close all rows before reordering. But I feel this is counterintuitive.

I’m using the DataView from piDog Software but I think the question is relevant both for a native listbox and for DataView. But please correct me if this is wrong.

Please explain in more detail what you want to do. A listbox either has ExpandableRows or is doesn’t . The same is true for AllowRowReordering. I don’t even know if you can change these during runtime.

I exclude some rows in the listbox with expandable rows from dragging like this:

Think of it like dragging folders around in Finder list view. The OP wants to prevent a user from dropping a row onto the contents of an expanded folder (preventing the user from nesting a folder).

Thank you @Beatrix_Willius for trying to help me – despite my poor explanation.
@Tim_Parnell your description is spot on, thanks

So you want to exclude (in Finder terms) dropping one folder onto another. You would have to forbid that at the drop moment, or at the MouseOver moment by not accepting the drop, or even when you start the drag.

Just for the sake of information, you can turn the whole quoted code into a single line:
Me.AllowRowReordering = Me.RowExpandableAt(Row)


@TimStreater, I guess that will only work if the “destination folder” isn’t expanded.
If “destination folder” is expanded the “source folder” will become a subfolder.
Screen Recording 2024-01-18 at 21.12.32

@Arnaud_N, Good point

In your listbox’s DragReorderRow event, add this code:

If parentRow=-1 then
     'This is an expandable row being dragged
     return false

This will at least prevent top-level expandable rows from being dragged.

Check for the parentRow in the DragOverRow event.
If the item is being dragged to the top level, parentRow will have a value of -1.
Otherwise return True in this event to prevent the drop to occur.

I’m not trying to prevent users from reordering expandable rows, @Eric_Williams. I’m trying to prevent them from nesting rows. Anyways DataView does not offer “DragReorderRow” or “parentRow” but “DragReorderRows”. I’ve tried working with this event. No joy yet :frowning:, but thanks.

@StefanA , I think you are pointing me in the same direction, but I can’t get my head around it, yet – thanks.

DataView does not offer “DragOverRow”, maybe I just can’t do it the same way in DataView as in DesktopListBox