TreeListBox Drag item but keep same depth

Grids for WPF Forum

Posted 2 months ago by BenjaminLopVic - France
Version: 24.1.2
Avatar

Hello,

I've implemented drag and drop functionality by referring to the CustomTreeListBoxItemAdapters in the TreeListBoxDragDropsample, but it's not working as I'd like. When you drag and drop an item, its depth can be changed. However, I want to prevent items from changing depth when moved, just like in Word, when you move headins in the Navigation Pane.

I've tried to modify the method myself, but I encountered a lot of strange behaviors, and I'm unsure how to make the drop area line indicator full width to show that the depth will not change.

Is there a simple way to make drag-and-drop maintain the current depth of an item even after it's been moved? 

Thank you in advance!

Benjamin.

[Modified 2 months ago]

Comments (1)

Answer - Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

We don't have a built in way to prevent dropping on items of different depth.  Your best bet would be to discover this scenario in your custom TreeListBoxItemAdapater's OnDragOver method and block dropping in that case via a "None" drop area, but also perhaps allow an "On" drop area when over a parent of the desired depth level.

If I insert this quick test logic in our TreeListBoxDragDrop QuickStart's OnDragOver method, it will block dropping on any target item that has an uppercase "R" in the name:

if ((targetItem is TreeNodeModel m) && (m.Name.Contains("R"))) {
	e.Effects = DragDropEffects.None;
	return TreeItemDropArea.None;
}

In your case, you'd want to make more complex logic that would calculate the depth of the item being dragged (firstItem) and the depth of the target item (targetItem).  If they don't match, use the "None" drop area result.  Or if the target is one level higher, use the "On" drop area result.


Actipro Software Support

The latest build of this product (v24.1.3) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.