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

Drag and Drop between Two TreeViews

3 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 23 Jul 2010, 01:34 PM

I have a problem which only seems to occur when using the Telerik RAD tree views , instead of the standard WPF treeview control

On a basic level, I have an application that loops through an OLAP cube and returns data to the interface treeview.  The treeview then displays the data in a format like below 

 + Measure
  Measure1
Measure2
Measure 3
Measure 4 etc

I want to be able to drag each individual node (e.g Measure 2 or Measure 3) into another treeview. However when dragging the measures, it drags the whole root (Measure) preventing me from separating the nodes.

Any idea how it could be made possible to drag individual nodes instead of the whole root??


The relevant XAML and XAML.cs is shown below

XAML
 <Telerik:RadTreeView x:Name ="treeCube" IsDragDropEnabled ="True" Margin="250,174,41,158" Background="White" Telerik:StyleManager.Theme="Windows7" ToolTip="Drag" AllowDrop="True">       
        </Telerik:RadTreeView>

        <Telerik:RadTreeView x:Name ="treeCubeTwo" IsDragDropEnabled ="True" Margin="0,174,-491,158" Background="White" Telerik:StyleManager.Theme="Windows7" Width="509" HorizontalAlignment="Right">        
        </Telerik:RadTreeView>

XAML.cs

 private void LoadCube_Click(object sender, RoutedEventArgs e)
            {

                // get the cube schema
                Helper helper = new Helper("demo01");
                helper.Catalog = "Adventure Works DW 2008R2";
                helper.Cube = "Adventure Works";

                _cube = helper.GetCubeSchema();

                // create an empty parameter set
                _params = new ParameterSet();

                // populate the left-hand treeview with cube schema

                // measures
                TreeViewItem measuresItem = new TreeViewItem();
                measuresItem.Header = "Measures";

                foreach (Measure measure in _cube.Measures)
                {
                    TreeViewItem measureItem = new TreeViewItem();
                    measureItem.Header = measure.Caption;
                    measuresItem.Items.Add(measureItem);
                }

                treeCube.Items.Add(measuresItem);




3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 27 Jul 2010, 03:36 PM
Hello James,

You must use the RadTreeViewItem instead TreeViewItem when using the RadTreeView.
Also you  can take a look at following articles:
http://www.telerik.com/help/silverlight/radtreeview-features-drag-and-drop.html .

Best wishes,
Hristo Milyakov
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
James
Top achievements
Rank 1
answered on 28 Jul 2010, 04:18 PM

Thanks Hristo,

That was quite obvious.
I do have another problem with this project though....

As I am looping through data and bringing it into the tree-view, there doesn't seem to be an effective way of stopping some nodes from being dragged. Ideally I wanted the root node (Measure) to be un-draggable, but the levels below it to be still be draggable.

I did try this using the code below to try and cancel the drag event once the program realised the item was the "Measure" node but only count seemed to be available with this function.

I am hoping there is a simple way to prevent this, as I also have a Dimension node with many levels below that would also need to be made undraggable in the future

        private void radTreeView_PreviewDragStarted(object sender, RadTreeViewDragEventArgs e)
        {
            Collection<Object> draggedItems = e.DraggedItems;
            if (measuresItem.Header.ToString() == "Measures")
            {
                MessageBox.Show("Not Allowed");
e.Handled = true;
            }
                else
            {

            }           
        }

Regards
James

0
Hristo
Telerik team
answered on 29 Jul 2010, 03:09 PM
Hello James,

I'm sending you an example showing how the PreviewDragStarted event can be handled easily. Also the treeview is bound to a ViewModel observable collection. I'm using property of the ViewModel (IsDraggable property of Measure object) to determine whether the object can be dragged or not.

Sincerely yours,
Hristo Milyakov
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
James
Top achievements
Rank 1
Answers by
Hristo
Telerik team
James
Top achievements
Rank 1
Share this question
or