Telerik RadTreeView拖动

时间:2011-04-18 06:16:36

标签: telerik radtreeview

当我在RadTreeView中使用ChildWindow时,即使我将IsDragDropEnabled属性设置为“True”,我也无法拖动项目。但是当我在RadTreeView中使用UserControl时,它可以拖动。

问题是什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

你必须开火事件

在构造函数

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;

    }

就是这样。