Disable Drag the parent TreeView

2 posts, 0 answers
  1. Nelson
    Nelson avatar
    62 posts
    Member since:
    Apr 2011

    Posted 22 Jul 2011 Link to this post

    Hello,

    There is some way to disable the drag of the parents on TreeViews?

    Thanks
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 26 Jul 2011 Link to this post

    Hi Nelson,

    The easiest way is to use the PreviewDragStarted event as shown bellow:

    <telerik:RadTreeView IsDragDropEnabled="True"
            PreviewDragStarted="RadTreeView_PreviewDragStarted">
        <telerik:RadTreeViewItem Header="Item 1">
            <telerik:RadTreeViewItem Header="Item 1" />
            <telerik:RadTreeViewItem Header="Item 2" />
            <telerik:RadTreeViewItem Header="Item 3" />
        </telerik:RadTreeViewItem>
        <telerik:RadTreeViewItem Header="Item 2">
            <telerik:RadTreeViewItem Header="Item 1" />
            <telerik:RadTreeViewItem Header="Item 2" />
            <telerik:RadTreeViewItem Header="Item 3" />
        </telerik:RadTreeViewItem>
        <telerik:RadTreeViewItem Header="Item 3">
            <telerik:RadTreeViewItem Header="Item 1" />
            <telerik:RadTreeViewItem Header="Item 2" />
            <telerik:RadTreeViewItem Header="Item 3" />
        </telerik:RadTreeViewItem>
    </telerik:RadTreeView>

    private void RadTreeView_PreviewDragStarted(object sender, Telerik.Windows.Controls.RadTreeViewDragEventArgs e)
    {
        bool handled = false;
     
        RadTreeViewItem treeViewItem = e.DraggedItems[0] as RadTreeViewItem;
        if (treeViewItem.Level == 0)
        {
            handled = true;
        }
     
        e.Handled = handled;
    }

    Give it a try and let me know how it goes.

    Best wishes,
    Kiril Stanoev
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
Back to Top