Get dragged item

5 posts, 1 answers
  1. annet
    annet avatar
    4 posts
    Member since:
    Nov 2010

    Posted 22 Sep 2011 Link to this post

    Hi all,

    I am using a RadTreeList with drag and drop enabled. This works fine.
    Now I want to prevent items at the highest level from being dropped on another item. These items cannot be the child of another item.

    How can I accomplish this?

    I think I can prevent the dropping of certain items in the itemDragging, but I don't know how to access the dragged_item here.
    Then I can do something like:
    if (level of the dragged item  is zero) then args.set_canDrop(false);

    Annet
  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 24 Sep 2011 Link to this post

    What if you do it on the server side in OnItemDrop and just check if the item draggings parent is null...if it is just set cancelled to true?

    http://www.telerik.com/help/aspnet-ajax/treelist-items-drag-drop.html

    Steve
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. annet
    annet avatar
    4 posts
    Member since:
    Nov 2010

    Posted 26 Sep 2011 Link to this post

    Thank you Steve, this prevents the actual dropping of the item, which I also needed to do.
    But during dragging, I would like to give the user a visible clue when an item can't be dropped.
    I use the client-side itemDragging for that, like in the Telerik demo.
    Can this be done?

    Annet
  5. Answer
    Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 26 Sep 2011 Link to this post

    Well setting cancel prevents the item being dropped if the condition is met, setting it globally clearly isn't the way to go :)

    So this is something I did recently
    public void OnWorkflowList_ItemDrop(object sender, TreeListItemDragDropEventArgs e) {
        var item = e.DraggedItems.First();
        var dataItem = item.DataItem as Approval;
     
        var approvalID = item.GetDataKeyValue("ApprovalID");
        var parentApprovalID = item.GetDataKeyValue("ParentApprovalID");
     
        Approval approval = base.RTOContext.Approvals.Get(new Guid(approvalID.ToString()));
        Approval parentApproval = null;
        if (parentApprovalID != null) {
            parentApproval = base.RTOContext.Approvals.Get(new Guid(parentApprovalID.ToString()));
        }
     
        //We're dragging to the header
        if (e.DestinationDataItem == null) {
            if ((approval.PickTypeID != (byte)WorkflowItemsTypeEnum.Assigned || approval.PickTypeID != (byte)WorkflowItemsTypeEnum.Assigned) && approval.ApproverID == null) {
                //Not possible to drag an unknown approver item to the root with nobody to pick it
                e.Canceled = true;
                commandMessageLiteral.Text = "Invalid Re-order, item has no defined approver, so nobody will be able to pick them (cats and dogs living together, mass hysteria)";
            }
        }
        else {
            //Check to see if the item we're dropping it on is approved, and this person doesn't have an approver assigned
            if (approval.ApproverID == null && (parentApproval.StatusType != StatusType.Pending || parentApproval.StatusType != StatusType.NotRequired || parentApproval.StatusType != StatusType.Empty)) {
                e.Canceled = true;
                commandMessageLiteral.Text = "Invalid Re-order, the item you're dropping it onto isn't pending, so nobody will be able to pick this person";
            }
        }
     
    }

    So this is the line that checks to see if it's being dragged into the header, and that's where you'd cancel with a message
    //We're dragging to the header
        if (e.DestinationDataItem == null) {

    NOW, clientside though it looks like it might be easy as well
    Handle OnItemDropping
    function onItemDropping(sender, args){
      var dataItem = args.get_targetDataItem();
       
      if(dataItem.get_isRoot()){
         args.set_cancel(true); //I believe this is how to cancel
      }
     
    }
    Now this is me just looking at the documentation and winging it, so I'm not entirely sure if that will work, but seems okay
  6. annet
    annet avatar
    4 posts
    Member since:
    Nov 2010

    Posted 26 Sep 2011 Link to this post

    Thanks for your input. I can't get it to work client-side, so I settled for the server-side solution.

    Annet
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017