Drag/Drop within a ListBox

34 posts, 0 answers
  1. Andy
    Andy avatar
    5 posts
    Member since:
    Nov 2011

    Posted 17 Nov 2011 Link to this post

    Thanks for the zip file. They works fine with Q2 assemblies. The only thing is that they still use Style Resource "DraggableListBoxStyle" that I don' want to use.

    I have put together a small applicatioin with Q2 dll and Drag/Drop events codes from one of your latest Example.cs files. I will appreciate if you fix my problem on this Application. Please search for the word "Problem"  in the project and here I am not able to get the Index of dropped location. You may just have to change 2 or 3 lines of code.

    I will really appreciate if you please make necessary changes so that I can
    •  Drop from one list box into other at desired location.
    • Reorder the individual List box.

    How can I send this project to you. I am not able to upload it. Only image files are enabled..
    BTW here is the .DropInfo Event where I want the fix.




    private void DropInfo(object sender, DragDropEventArgs e)





    ItemsControl wishlist = e.Options.Destination as System.Windows.Controls.ItemsControl;




    ICollection draggedItems = e.Options.Payload as ICollection;




    // Get the drag cu that the TreeView or we have created







    TreeViewDragCue cue = e.Options.DragCue


    as TreeViewDragCue;




    if (e.Options.Status == DragStatus.DropPossible)





    // Set a suitable text:







    cue.DragActionContent =


    String.Format("Add {0} item{1} to Wishlist", draggedItems.Count, draggedItems.Count > 1 ? "s" : String.Empty);


    cue.IsDropPossible =







    // wishlist.Background = this.Resources["BasicBrush"] as Brush;










    else if (e.Options.Status == DragStatus.DropImpossible)



    cue.DragActionContent =




    cue.IsDropPossible =







    else if (e.Options.Status == DragStatus.DropComplete && e.Options.Destination is ListBox)






    ListBox listBoxSender = sender as System.Windows.Controls.ListBox;





    IList items = wishlist.ItemsSource as IList;




    IList<MachineScheduleViewModel> itemsSource = wishlist.ItemsSource as IList<MachineScheduleViewModel>;




    foreach (object draggedItem in draggedItems)















    var destinationIndex = 2;// itemsSource.IndexOf((MachineScheduleViewModel)wishlist.DataContext);









    var operation = draggedItem as DragDropOperation;




    // var operation = e.Options.Payload as DragDropOperation;










    //Problem here ****************************************************************************










    // How can I get the actual insert Index... I have hard coded index = 2 and the dragged items are









    // getting inserted there at idex 2.









    var insertIndex =0;




    if(itemsSource.Count > 2)


    insertIndex = 2;


    // operation.DropPosition == DropPosition.Before ? destinationIndex : destinationIndex + 1;














    insertIndex = itemsSource.Count;




    // Please fix this so that I can get the actual index ****************









    itemsSource.Insert(insertIndex, (






    ListBox listBox = (ListBox)wishlist;


    listBox.Dispatcher.BeginInvoke(() =>


    listBox.SelectedIndex = insertIndex;





    // items.Add(draggedItem); //original











    if (e.Options.Status != DragStatus.DropPossible)



    wishlist.Background =


    new SolidColorBrush(Colors.White);




  2. Tsvyatko
    Tsvyatko avatar
    832 posts

    Posted 18 Nov 2011 Link to this post

    Hi Andy,

     You can attach project by opening support ticket. I encourage you to do so. that way we will be able to update it and provide solution in the specific case. Also, keep in mind that support tickets response time is shorter, so you will be able to receive response faster.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
  4. Trang
    Trang avatar
    8 posts
    Member since:
    May 2012

    Posted 12 Jul 2012 Link to this post

    I have this latest version but the autoscrolling does not work.  Please advise.

  5. NRT
    NRT avatar
    7 posts
    Member since:
    Jan 2013

    Posted 31 Jan 2013 Link to this post

    Hello , 
    Can I get an example where I can reorder/drag drop items WITHIN the SAME listbox which has vertically alligned items.
    I want a seperator also to indicate that we can drop the item in that position. 
     Please find the attachment. 
Back to Top