无法在radtreeview中使用拖放

时间:2011-03-21 14:19:22

标签: radtreeview

我已将所有数据绑定到RadTreeView,但无法使用drag-'n-drop。我使用了四个属性

IsDragDropEnabled="True" 
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"

我想在同一棵树中删除一个项目。但它不起作用。

3 个答案:

答案 0 :(得分:1)

这里有很多信息:http://www.telerik.com/help/silverlight/raddraganddrop-events.html

但是我也遇到树视图的问题。

答案 1 :(得分:1)

快速阅读this telerik article后,拖放似乎对我来说效果很好。

<telerik:RadTreeView ... EnableDragAndDrop="true" OnNodeDrop="MyTreeView_NodeDrop">

EnableDragAndDrop和OnNodeDrop似乎是让它工作的两个重要部分,但不在您尝试的属性列表中。 HTH

答案 2 :(得分:1)

 <telerik:RadTreeView x:Name="treeView1" IsDragDropEnabled="True" Margin="2,0,0,0" ItemsSource="{Binding SelectedSectionList, Mode=TwoWay}" ItemTemplate="{StaticResource SectionTemplate}" IsEditable="True" SelectedItem="{Binding SelectedCustomSectionList, Mode=TwoWay}" Grid.Column="2">

现在在

背后的代码中

你必须开火事件

在构造函数

this.treeView1.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);

然后

 private void OnDropQuery(object sender, DragDropQueryEventArgs e)
    {
        RadTreeViewItem destinationItem = e.Options.Destination as RadTreeViewItem;
        object source = this.GetItemFromPayload<object>(e.Options.Payload);
        object target = destinationItem != null ? destinationItem.Item : null;
        DropPosition position = destinationItem != null ? destinationItem.DropPosition : DropPosition.Inside;

        if (source != null && target != null)
        {
            Section sourceSection = source as Section;
            Section targetSection = target as Section;
            Question sourceQuestion = source as Question;
            Question targetQuestion = target as Question;

            if (sourceQuestion != null)
            {
                try
                {

                    if (sourceQuestion != null && targetQuestion != null && object.ReferenceEquals(sourceQuestion, targetQuestion))
                    {
                        sourceSection.Questions.Remove(sourceQuestion);
                        targetSection.Questions.Add(sourceQuestion);
                        e.QueryResult = false;
                        return;
                    }

                    if (targetQuestion != null && position == DropPosition.Inside)
                    {
                        sourceSection.Questions.Remove(sourceQuestion);
                        targetSection.Questions.Add(sourceQuestion);
                        e.QueryResult = false;
                        return;
                    }

                    if (position != DropPosition.Inside && targetQuestion == null)
                    {
                        sourceSection.Questions.Remove(sourceQuestion);
                        targetSection.Questions.Add(sourceQuestion);
                        e.QueryResult = false;
                        return;
                    }
                }
                catch (Exception ex)
                {


                }
            }
        }
        else
        {
            e.QueryResult = false;
            return;
        }
        e.QueryResult = true;

    }

就是这样。你可以拖放。