Tell users why they cannot drop.

5 posts, 1 answers
  1. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 09 Aug 2010 Link to this post

    Hello,
    Can someone please tell me the best way to indicate to a user why he cannot drop into a node.

    For the sake of a contrived example, lets say there are three nodes

        Smith
        Brown
        Bloggs

    I do not want to allow the Brown or Boggs nodes to be dropped into Smith, because Smith does not begin with a 'B'.

    I believe I know how to actually prevent the drop using DropQueryEvent but what would be the best way of indicating to the user the reason he cannot do the drop.

    I am hoping there might be some sort of Tooltip thing but anything practical will do.

    Many thanks.

  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 11 Aug 2010 Link to this post

    Hello Meerkat,

    Yes, with the DragQuery event you can say that a drop should not be possible. Either there or in the DropInfo event with status "DropImpossible" you can access the e.Options.DragCue object.

    In the case of the TreeView this object is the TreeViewDragCue which is an ItemsCotnrol that has the DragTooltipContent/Template and DragTooltipAction/Template are the properties that are looking for. They normally contain the current drop target and the drop action.

    Regards,
    Miroslav
    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. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 12 Aug 2010 Link to this post

    Hello Miroslav,

    I tried unsuccessfully to find a clue in your documention about how your suggestions might be used to display a tooltip that said "You Cannot drop here because Smith does not begin with B", when the mouse hovered over Smith,

    I fully appreciate that as Telerik  gets bigger it becomes harder to find the time to keep the documentation complete and up to date and also to provide the excellent service of the past.

    Nevertheless, I will definitely be back searching for your advice in the future :-)

    Many thanks anyway for your help on my current problem..
     
    Regards

    Meerkat


  4. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 17 Aug 2010 Link to this post

    Hi Meerkat,

    Indeed, this example was not available in the documentation. It will be added with a coming update.

    I could not make out if you have managed to use these properties - I am attaching a  sample project where this is shown.

    We have always tried to listen and I can only urge you to point out things that can be improved.

    Thanks for the feedback!

    Best wishes,
    Miroslav
    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
  5. Meerkat
    Meerkat avatar
    64 posts
    Member since:
    Feb 2007

    Posted 17 Aug 2010 Link to this post

    Many thanks for the example Miroslav
    I needed to make one or two minor changes to get things to work as in my case the tree is databound, but things seem to be working fine now. Smashing !

    Regards,

    Meerkat.


    private void OnDropQuery(object sender, DragDropQueryEventArgs e)
    {
      var destination = e.Options.Destination as RadTreeViewItem;
      var cue = e.Options.DragCue as TreeViewDragCue;
      
      // Do not allow dropping inside items which start with "B", only handle cases 
      // where a drop is currently allowed.
      
      TreeItem destItem = destination.Item as TreeItem;
      
      if (destination != null
        && e.Options.Status == DragStatus.DropDestinationQuery
        && e.QueryResult == true
        && destination.DropPosition == DropPosition.Inside
        && destItem.NodeText.StartsWith("B"))
      {
        // Denying a drop will set the cue.IsDropPossible = false
        e.QueryResult = false;
      
        // We only need to give a reason:
        cue.DragActionContent = "Cannot drop into Bs";
      }
    }
Back to Top