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

Treeview and ListBox DragAndDrop

11 Answers 70 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jean michel
Top achievements
Rank 1
jean michel asked on 28 Apr 2010, 01:47 PM
Hello people.

I have a ListBox with DragAndDrop and would like to move the items on this list for adding a Treeview node.

I appreciate the help.

11 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 29 Apr 2010, 05:01 PM
Hello jean michel,

Please take a look at the How to Implement Drag and Drop Between TreeView and Other Controls article and let me know if this is what you had in mind or if you need more info.

Regards,
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
jean michel
Top achievements
Rank 1
answered on 29 Apr 2010, 08:50 PM
Hello Tina,

This error occurs when compiling.

In line with this error below.

In the event: OnListBoxDragQuery

 
var payload = meusPapeisBox.SelectedItems.Cast<object>().ToList();

Error: System.Collections.Ilist does not contain a definition for Cast

My XAML:

  

<ListBox x:Name="meusPapeisBox" Margin="10 40 10 10" 
                         BorderThickness="0"   
                        ItemContainerStyle="{StaticResource draggableItemStyle}">  
                            <ListBox.ItemTemplate> 
                                <DataTemplate> 
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0 0 25 0">  
                                        <Image Source="{Binding DescricaoImagem}" Margin="0 0 3 0" Width="55" Height="55"   
                                        HorizontalAlignment="Center">  
                                            <ToolTipService.ToolTip> 
                                                <ToolTip Content="{Binding Descricao}"></ToolTip> 
                                            </ToolTipService.ToolTip> 
                                        </Image> 
                                        <StackPanel Orientation="Vertical" Width="80" Height="55" > 
                                            <TextBlock Text="{Binding Nome}" HorizontalAlignment="Left" FontWeight="Bold" /> 
                                            <TextBlock Text="{Binding Descricao}" HorizontalAlignment="Left"  TextWrapping="Wrap"  FontStyle="Italic" /> 
                                        </StackPanel> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </ListBox.ItemTemplate> 
                            <ListBox.ItemsPanel> 
                                <ItemsPanelTemplate> 
                                    <Primitives:RadUniformGrid  
                                HorizontalAlignment="Left" VerticalAlignment="Top" Columns="4" /> 
                                </ItemsPanelTemplate> 
                            </ListBox.ItemsPanel> 
                        </ListBox> 
0
jean michel
Top achievements
Rank 1
answered on 29 Apr 2010, 10:03 PM
Hi,

I discovered the problem has to import System.Linq

But now I'm having another problem

How can I move to the Treeview the properties DefaultImageSrc and Header from the selected object

0
Tina Stancheva
Telerik team
answered on 05 May 2010, 11:35 AM
Hello jean michel,

Please accept my apology for the delayed response.

I am not sure that I understand your scenario correctly.

However, I prepared a sample project for you, illustrating how you can drag and drop items from ListBox to RadTreeView. The ListBox items are databound to a business object, with two properties - EmployeeName and IconPath. Also ListBoxItems can only be dropped among the Employee collection in the RadTreeView and when the item is dropped a new item is added in the RadTreeView - Employee with Name = EmployeeName and DefaultImageSrc = IconPath.

Please take a look at the project and let me know if this is what you had in mind or if you need more info.

Best wishes,
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
jean michel
Top achievements
Rank 1
answered on 05 May 2010, 09:57 PM
Solution:

In the event onDropInfo:

if (e.Options.Status == DragStatus.DropComplete)  
                {  
                    if (destinationItem != null && papeis != null)  
                    {  
                        foreach (var item in papeis)  
                        {  
 
                            destinationItem.Items.Add(new Telerik.Windows.Controls.RadTreeViewItem()  
                            {  
                                Header = item.Nome,  
                                DefaultImageSrc = item.DescricaoImagem,  
                            });  
 
                            destinationItem.IsExpanded = true;  
 
                            statusDrag = 0;  
 
 
                        }  
 
                        foreach (Telerik.Windows.Controls.RadTreeViewItem itens in RadHierarquia.Items)  
                        {  
                            LoadTreeView(itens);  
                        }  
 
 
                        e.Handled = true;  
 
                    } 
0
jean michel
Top achievements
Rank 1
answered on 06 May 2010, 09:03 PM
Hello Tina,

I implemented your example, but because I can not insert the item in the listbox item in the TreeView? Is only possible to insert before or after the item from the TreeView.

Thanks.
0
Tina Stancheva
Telerik team
answered on 07 May 2010, 10:43 AM
Hello jean michel,

If the RadTreeView is databound to a business object, when you are dropping the items in the TreeView you won't be able to easily get the new RadTreeViewItem that is created to nest the dropped object. Therefore it would be hard to display the Image from the ListBoxItem using the DefaultImageSource.

I attached a new project that illustrates  how to  drag items from the ListBox and drop them into certain TreeViewItems (in this case you can drop items before or after an employee and inside a department in the TreeView). Also please note that I added an IconPath property to the Employee class and also added an Image to the EmployeeTemplate in order to allow images to be displayed in front of the employees.

This solution is much better than the one, using the DefaultImageSource property of the RadTreeViewItem to display the dragged image. Please give it a try and let me know if it works for you.

Regards,
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
jean michel
Top achievements
Rank 1
answered on 07 May 2010, 02:47 PM
The problem is when I position the item on the item treview. The option to insert within the item is not enabled
0
Tina Stancheva
Telerik team
answered on 07 May 2010, 03:06 PM
Hello jean michel,

Sorry about that, I left out the constructor for the Employee class.
I also modified the OnTreeViewDropInfo() event handler to include dropping items into the Employees branch.

Let me know if I can assist you further.

Greetings,
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
jean michel
Top achievements
Rank 1
answered on 07 May 2010, 07:06 PM
Tina,

Ok, it worked thank you.

Now I'm trying to do the same with the TreeView example Self-reference hierarchy and I'm having the same problem.
0
Tina Stancheva
Telerik team
answered on 13 May 2010, 12:23 PM
Hello Jean Michel,

I attached a couple of projects demonstrating how you can use a HierarchyConverter that allows you to implement the drag and drop functionality that you are looking for. Please take a look at them and let me know if you need more info.

All the best,
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.
Tags
TreeView
Asked by
jean michel
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
jean michel
Top achievements
Rank 1
Share this question
or