This is a migrated thread and some comments may be shown as answers.

TreeView to Listbox

5 Answers 75 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Lone
Top achievements
Rank 1
Lone asked on 05 Feb 2010, 06:00 AM

I am havig problems grasping the event handlers. I understand each one and its purpose, what I dont understand is what commands to put in the even that handles the drag from the treeView. The treeview items shud be dragged to populate the listbox, but not removed. So basically, each drag will copy the item into the list box, which means multiple instances of one item can exist in the list box. I want ot know how to create the on drag query and info events for the tree, as the demo has not helped me as adequately as I hoped it would have. I have this, for the list box on drophandler event, I am not sure what should go into the dropquery function.

private void OnListDropHandler(object sender, DragDropEventArgs e)
{
System.Windows.Controls.ItemsControl LessonList = e.Options.Destination as System.Windows.Controls.ItemsControl;
ICollection draggedItems = e.Options.Payload as ICollection;

// Get the drag cu that the TreeView or we have created
TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue;

if (e.Options.Status == DragStatus.DropPossible)
{
// Set a suitable text:
cue.DragActionContent = String.Format("Add {0} item{1} to Lesson List", draggedItems.Count, draggedItems.Count > 1 ? "s" : String.Empty);
cue.IsDropPossible = true;
//order.Background = this.Resources["DropPossibleBackground"] as Brush;
}
else if (e.Options.Status == DragStatus.DropImpossible)
{
cue.DragActionContent = null;
cue.IsDropPossible = false;
}
else if (e.Options.Status == DragStatus.DropComplete)
{
IList items = LessonList.ItemsSource as IList;
foreach (object draggedItem in draggedItems)
{
items.Add(draggedItem);
}
}

if (e.Options.Status != DragStatus.DropPossible)
{
LessonList.Background = new SolidColorBrush(Colors.White);
}
}

is this ok? and how would I go about setting up the rest?

Thanks in advance

5 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 10 Feb 2010, 02:41 PM
Hi Lone Crusader ,

I prepared a sample that demonstrates how to drag items from a hierarchial RadTreeView to a ListBox.

In the sample the dragged items from the RadTreeView are not deleted and you can put multiple instances of an item into the listBox.

Please let us know if you need more info.

Best wishes,
Tina Stancheva
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Scott
Top achievements
Rank 1
answered on 27 Feb 2010, 07:42 AM
This is exactly what I want to do, but my items don't drag/drop. The OnDragQuery, OnDropQuery, and OnDropInfo events are never invoked, although they are set right after the initialize.  I tried dropping into textboxes and listboxes.  I can't figure out why this isn't working!

I do notice that in the TreeView drag/drop demo, you set event handlers different:

            this.TextBox_DropConsumer.AddHandler(RadDragAndDropManager.DropQueryEvent, 
                new EventHandler<DragDropQueryEventArgs>(TextBox_OnDropQuery)); 
 
            this.TextBox_DropConsumer.AddHandler(RadDragAndDropManager.DropInfoEvent, 
                new EventHandler<DragDropEventArgs>(TextBox_OnDropInfo)); 
 
            this.RadGridView_DropConsumer.AddHandler(RadDragAndDropManager.DropQueryEvent, 
                new EventHandler<DragDropQueryEventArgs>(RadGridView1_OnDropQuery)); 
 
            this.RadGridView_DropConsumer.AddHandler(RadDragAndDropManager.DropInfoEvent, 
                new EventHandler<DragDropEventArgs>(RadGridView1_OnDropInfo)); 

However, that way doesn't work either.  They are never called.
0
Tina Stancheva
Telerik team
answered on 04 Mar 2010, 08:15 AM
Hello Scott,

I have updated the example by adding TextBlock and RadGridView controls and DragAndDrop functionality for them.

Take a look at it and let me know if it helps.

If you still have problems with your code, perhaps you can send me a sample so that I can further investigate your issues.

Please do not hesitate to contact us for any additional info.

Sincerely yours,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Linus
Top achievements
Rank 1
answered on 01 Jul 2011, 01:58 PM
This is very interesting as I have spent a day or so trying to get drag/drop work between a treeview and a listbox. I have tried your example project here but it doesn't work. Maybe is it outdated? I use version 2011.1.419.1040. I would very much appreciate a working sample of the above project. I would also very much like to have two things
explained:

1. What do I have to do to change the default visual cue to indicate the drop is possible? I don't mean I want my custom styling, I just want it to show that the drop is possible but in my project now I have drag/drop working but the icon is always saying it's not allowed to drop.

2. What decides that the treeview should remove the treeviewitem on a successful drop and how do I change this behavior?

I have read as much documentation I can find on this but it's still very confusing.

I would very much appreciate some help on this, it's driving me crazy.

Thanks,
Linus
0
Tsvyatko
Telerik team
answered on 04 Jul 2011, 08:03 AM
Hi Linus,

Since, our last response, we have many improvements to our DnD logic. You might want check these help articles that describes how achieve the desired functionality:

 - http://www.telerik.com/help/silverlight/radtreeview-how-to-implement-drag-and-drop-between-treeview-and-other-controls.html
 - http://www.telerik.com/help/silverlight/radtreeview-how-to-implement-copy-drag.html


In addition you can control TreeViewDragCue forbidden icon visibility by setting TreeViewDragCue.IsDropPossible property.

I hope this helps.

Kind regards,
Tsvyatko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
DragAndDrop
Asked by
Lone
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Scott
Top achievements
Rank 1
Linus
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or