can u please provide sample code of Drag and Drop functionality for TreeListbox

Grids for WPF Forum

Posted 3 years ago by naveen gampa
Version: 21.1.1


I need to impliment Drag and Drop functionality for Treelistbox items to change the Priority.I have gone through the Actipro documentation and came across the below  link

I tried by following the above documentation but facing issues like when i try to drag it is not hitting the OnDragStart and other methods. can u please post some sample example with code so that i can use that and impliment in my application.

[Modified 3 years ago]

Comments (4)

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA


We have a drag and drop sample for TreeListBox in our Sample Browser project.  Here's the link to the GitHub repo source of that particular "/ProductSamples/GridsSamples/QuickStart/TreeListBoxDragDrop" sample within the project.

Actipro Software Support

Posted 2 years ago by naveen gampa

HI, Thanks for Providing the sample. but we are facing issues because while changing the order  unable to find the index .

1.I need to get the latest index values of all items after changng the order becuase i need to print / save with that order.

2.Unable to find the where the final target value is stored.

3.unable to select the reordered items.

4. Can u provide without using Parent children relationship.

can u please help us on this..

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


The TreeListBox is a complicated control because it fitting a tree structure of your items and presents them in a "flat" list.  It is completely geared around MVVM design.  While it is an ItemsControl, the actual items bound to ItemsSource is a collection of an internal tree node type where each node wraps one of your items.

1) There isn't really a concept of item "index" in the control itself since the (1) the control is virtualized and (2) the display index depends on what is expanded/collapsed above it.  If you need to know the index of items, you would need to make a tree walker for your MVVM tree and walk the tree.  Increment the current index for each item you encounter.  As long as you use an ObservableCollection for your item's collection of child items, it should all be up to date after drag/drops and in the proper order that is rendered in the control.

2) The TreeListBoxItemAdapter.OnDrop method is called when a drop occurs and tells you the targeted item.  You then determine how the drop occurs in your implementation of that method.  You are in control of where the drop goes.

3) Our sample TreeListBoxItemAdapter.OnDrop method shows how to focus the dropped item.

4) The TreeListBox is designed to be used with a MVVM tree structure of your items that have parent/child relationships.  If you can't have that kind of setup, then unfortunately you might need to use a different control that TreeListBox.

Actipro Software Support

Posted 2 years ago by naveen gampa

Thanks for the help. we made it and working fine. hoping we get the response with same speed for other questions we post

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.