Problems with Drag&drop and some components

6 posts, 1 answers
  1. Luís Pinheiro
    Luís Pinheiro avatar
    3 posts
    Member since:
    Feb 2010

    Posted 15 Apr 2010 Link to this post

    Hello everybody.

    i started to development whit telerik components this days and i'm really confused with drag&drop events
    (i guess that isn't a telerik components problem. hehe)

    Let me explain my needs and then show my problems.

    I need to create a component like the "windowns media player" (it's the basic ideia). Manipulate files (audio/video) and create playlists (with audio and/or video files)
    i'm using a GridView containing all files without repeat and a TreeView containing all created playlist's and the files inside the playlist (as hierarchical items). Up there is all right, i've created all components and functions without problem.

    But i need to drag&drop between them and I have some rules:
     - when dragging from gridVIew and dropping in the treeView:
    i need to maintain all the selected files inside the GridView and add copies in the "selected" playlist
     - when dragging from treeView and dropping in the gridView:
    i need to exclude all select files in the treeview (even if i select files in different playlist's) and don't create anything in the GridView
     - when dragging and dropping in treeView:
    i need to update the sources only if the playlist's change.


    So far, i can drag from treeview and exclude the file but only one file, if i select more I got a "reference problem" in this line:
    ExcludeFile (draggedItem as FileDto, (e.Options.Source as RadTreeViewItem).ParentItem.Item as PlaylistDto);
    the property ParentItem is set to "null", so the ExcludeFile function can't run.
    (FileDto is a Class containing properties about the files and PlaylistDto is a class containing playlist's properties)


    When i'm tring to add files in the playlist (drag from GridView to TreeView) i have another problem that is: nothing!!!
    yeah, nothing happens! I see the DragCue (with my template) then I drop where i want and the Cue just close without add the file in the playlist and i got no errors in the Code.


    so, i guess that is "only" this... hehehe
    I don't have a good english, so if you do not understand anything, just let me know and I will try to explain in another way.
    I hope somebody can help me, please. =)

    Thank you very much.
    Luís Alberto.



    By the way: Telerik is really, really great. Everyone who worked for it deserve the credit. I liked so much.
    Congratulations!
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 21 Apr 2010 Link to this post

    Hello Luís Pinheiro,

    Please accept my apology for the delayed response.

    I am not sure if I understand your scenario correctly. However, I prepared a sample project demonstrating DradAndDrop between RadGridView and RadTreeView.

    I also implemented the rules you mention:
    1. The items from the GridView are copied to the TreeView on a drag/drop operation. For this purpose the RadGridView OnDragQuery() event is handled.

    2. The RadTreeView dragged items are deleted when dropped onto RadGridView. For this purpose the RadGridView OnDropQuery() event is handled.

    3. When items are dragged and dropped inside the RadTreeView the PreviewDragEnded() event is handled to deny dropping outside the main nodes of the tree.

    Please take a look ta the project and let me know if it helps or if your scenario requires a different approach.

    Best wishes,
    Tina Stancheva
    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. Luís Pinheiro
    Luís Pinheiro avatar
    3 posts
    Member since:
    Feb 2010

    Posted 23 Apr 2010 Link to this post

    Hello Tina,

    Thanks for you attention and don't worry about the delay, the best isn't fast. Hehe
    Your solution is really great. Perfect! Thank you very much.

    I liked most of this part
    <telerikGrid:RadGridView.RowStyle> 
      <Style TargetType="telerikGridElements:GridViewRow"
        <Setter Property="telerikDragDrop:RadDragAndDropManager.AllowDrag" Value="True" /> 
      </Style> 
    </telerikGrid:RadGridView.RowStyle> 
    I tried to do this but I never got.

    But not everything is flowers. I have a new doubt. Your solution is good and simple enough for learning so let's keep using it.
    If we tried to re-order the columns or group them, whenever you drag the grid header, we have a unknow error (by me) and all the design disappears. I can disable this features, but it will be a big problem in the future.
    So, how I fix this? Keep the re-order/grouping and the drag&drop working together.


    Thanks again for your attention.
    Luís Alberto
  4. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 24 Apr 2010 Link to this post

    Hi Luís Pinheiro,

    I managed to reproduce the problem and I modified the GridView OnDragInfo , like so:

    private void OnGridViewDragInfo(object sender, DragDropEventArgs e)
            {
                RadGridView gridView = sender as RadGridView;
                ProductViewModel draggedItem = e.Options.Payload as ProductViewModel;
     
                if (e.Options.Status == DragStatus.DragInProgress && draggedItem != null)
                {
                    //Setting up a drag cue:
                    ContentControl cue = new ContentControl();
                    //Choosing a template for the items:
                    cue.ContentTemplate = this.Resources["descriptionTemplate"] as DataTemplate;
                    cue.Content = draggedItem;
                    e.Options.DragCue = cue;
     
                }
            }

    Can you please give it a try and let me know if it works for you?

    Best wishes,
    Tina Stancheva
    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. Luís Pinheiro
    Luís Pinheiro avatar
    3 posts
    Member since:
    Feb 2010

    Posted 04 May 2010 Link to this post

    Hello Tina,


    Now I need to apologize my delay. I was a little excited with the VisualStudio and SilverLight news that i forgot take a look to the forum.
    Great! It works perfectly!

    Thank you so much for your help.

    My best wishes,
    Luís Alberto
  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 06 May 2010 Link to this post

    Hello Luís Pinheiro,

    i am glad I was able to help.

    Please let me know if I can further assist you.

    All the best,
    Tina Stancheva
    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.
Back to Top