Drag and Drop between Two TreeViews

4 posts, 0 answers
  1. James
    James avatar
    5 posts
    Member since:
    Jul 2010

    Posted 23 Jul 2010 Link to this post


    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);




  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 27 Jul 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. James
    James avatar
    5 posts
    Member since:
    Jul 2010

    Posted 28 Jul 2010 Link to this post


    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

  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 29 Jul 2010 Link to this post

    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
Back to Top