Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

How to create a ListBox with dragable/movable (drag & drop) item?

ReignBough
Enthusiast
I am creating a dialog with list box. The items should me dragable/movable to any row. I am using ListBoxObserver but I am unable to do it.
~ReignBough~
ARCHICAD 26 INT (from AC18)
Windows 11 Pro, AMD Ryzen 7, 3.20GHz, 32.0GB RAM, 64-bit OS
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Oleg
Expert
There is 2 way

1. Full Drag-Drop

Call the EnableDragAndDropEvent() for panel (dialog)

Implement Drag-Drop handlers of the ListBoxObserver (ListBoxDragSourceObserver, ListBoxDropTargetObserver), at last
ListBoxDragStarting, ListBoxDragStarted, ListBoxDragEntered, ListBoxDragMoved, ListBoxDropped

2. Simple row dragging

Create an "drag" icon column. Fill it the DG::ListBox::DragIcon or any other.

Call list.EnableMouseMoveEvent() for the list box

Implement ListBoxMouseMoved( const DG::ListBoxMouseMoveEvent& ev, short* inArea );
When a mouse will be over the drag icon column, assign *inArea = DG::ListBox::DragArea.

Implement ListBoxItemDragged( const DG::ListBoxDragEvent& ev ) to handle dragging

View solution in original post

2 REPLIES 2
Solution
Oleg
Expert
There is 2 way

1. Full Drag-Drop

Call the EnableDragAndDropEvent() for panel (dialog)

Implement Drag-Drop handlers of the ListBoxObserver (ListBoxDragSourceObserver, ListBoxDropTargetObserver), at last
ListBoxDragStarting, ListBoxDragStarted, ListBoxDragEntered, ListBoxDragMoved, ListBoxDropped

2. Simple row dragging

Create an "drag" icon column. Fill it the DG::ListBox::DragIcon or any other.

Call list.EnableMouseMoveEvent() for the list box

Implement ListBoxMouseMoved( const DG::ListBoxMouseMoveEvent& ev, short* inArea );
When a mouse will be over the drag icon column, assign *inArea = DG::ListBox::DragArea.

Implement ListBoxItemDragged( const DG::ListBoxDragEvent& ev ) to handle dragging
ReignBough
Enthusiast
Thank you.

The error in my code was in ListBoxMouseMoved() function since I follow the documentation:
virtual void ListBoxMouseMoved (
    const ListBoxMouseMoveEvent & ev,
    bool *              inDragArea
);
It is now working after I changed it to short.
~ReignBough~
ARCHICAD 26 INT (from AC18)
Windows 11 Pro, AMD Ryzen 7, 3.20GHz, 32.0GB RAM, 64-bit OS