Drag Drop Problem

12 posts, 0 answers
  1. Scott Rakestraw
    Scott Rakestraw avatar
    84 posts
    Member since:
    Sep 2005

    Posted 10 Jul 2012 Link to this post

    I have a radlistbox with drag & drop enabled for reordering the list.  On the same UI is a radgrid.  I do not have drag drop enabled on that grid.  If I drag an item from the radlistbox and drop it on the grid it then disappears from the listbox.  What I want is to limit the drag drop to only allow reordering of the radlistbox.  I'm not sure what is going on.
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 11 Jul 2012 Link to this post

    Hi Scott,

      Could you share the XAML for your RadListBox and the RadGridView? If you are only intending on enabling the reorder you may need to write an event handler for the DragLeave or the Drop event. I prefer the Drop event, because this will let me use the DragCues to let the user know where the item is droppable.

     In the event handler do a check to see if the target is the RadListBox. If it is not, then cancel the drag operation. That will effectively return the ListBox item to where it was before the Drag operation.

      You can find the documentation for the Events of the DragDropManager here. And also the DragDropManager's documentation for RadListBox behavior here.

    Good Luck,
    Lancelot
  3. DevCraft banner
  4. Scott Rakestraw
    Scott Rakestraw avatar
    84 posts
    Member since:
    Sep 2005

    Posted 12 Jul 2012 Link to this post

    I appreciated the help and I've made some progress on this but can't seem to get the last part figured out.  I switched to a regular listbox and the drag and drop is working but I can't seem to tie to the drop event.  

    I tried doing DragDropManager.AddDropHandler(rlbColumns, New DragEventHandler(AddressOf OnElementDrop)) but it never fired.  I'm not sure what I'm doing wrong trying to capture this event.

    <UserControl.Resources>
     
        <DataTemplate x:Key="ListBoxItemTemplate">
            <StackPanel Orientation="Horizontal">
                <CheckBox ClickMode="Press" IsChecked="{Binding IsVisible, Mode=TwoWay}" Margin="5, 0, 0, 0" />
                <TextBlock Text="{Binding Name}" />
            </StackPanel>
        </DataTemplate>
     
        <Style x:Key="DraggableListBoxItem" TargetType="ListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
        </Style>
         
    </UserControl.Resources>
     
        <ListBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="rlbColumns" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MaxHeight="400" MinWidth="200" ItemContainerStyle="{StaticResource DraggableListBoxItem}" ItemTemplate="{StaticResource ListBoxItemTemplate}">
            <drag:ListBoxDragDrop.Behavior>
                <drag:ListBoxDragDropBehavior AllowReorder="True" />
            </drag:ListBoxDragDrop.Behavior>
            <telerik:ListBoxDragDrop.DragVisualProvider>
                <telerik:ScreenshotDragVisualProvider />
            </telerik:ListBoxDragDrop.DragVisualProvider>
        </ListBox>
  5. Scott Rakestraw
    Scott Rakestraw avatar
    84 posts
    Member since:
    Sep 2005

    Posted 12 Jul 2012 Link to this post

    Is there no way to scroll the listbox while you are dragging?  I can't seem to make that work either.
  6. George
    Admin
    George avatar
    1332 posts

    Posted 16 Jul 2012 Link to this post

    Hello Scott,

    I would suggest using the RadListBox control instead of the ListBox control. Using the drag&drop behaviors, you could inherit the ListBoxDragDropBehavior and override the Drop method instead of handling the Drop event. The behavior uses the drag&drop events and exposes virtual methods and it eases the implementation. Please, refer to our online demos here for more information about how to use drag and drop with RadListBox control - http://demos.telerik.com/silverlight/#ListBox/DragDrop 

    According to the second question - this feature is still in a progress and we are working on it. Most probably we will release it with the upcoming Q2 SP1 release.

    Kind regards,
    George
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 19 Jul 2012 Link to this post

    Hello,

    I need a suggestion to this issue:
       
       i designed a drag & drop listbox to listbox. I used drag & drop function from telerik sample. Its working fine.
    But in some cases, I see dragstatus = InProgress & dropstatus is in pending (or) Impossible. Which works fine in certain circumstances.

    looking for the Resolution,
    smb
  8. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 24 Jul 2012 Link to this post

    Hello

    I noticed that you have posted about this issue in this forum post too, can we continue the discussion there?

    All the best,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Manoj
    Manoj avatar
    5 posts
    Member since:
    May 2011

    Posted 07 Jun 2013 Link to this post

    Hello,

    In continuation with above asked question, I would like to know if scroll while dragging is supported now. I have number of items in listbox. I want to scroll item from top of my listbox to last of the list. There is a scroll on the listbox. It lets me drag only upto visible items in the listbox. If I want to drag beyond that, automatic scroll should have worked. But it is not working. I also tried same on your demo site at http://demos.telerik.com/silverlight/#ListBox/DragDrop. But here also this is not working.

    Can you tell me how to make this work?

    Thanks,
    Manoj Attal
  10. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 10 Jun 2013 Link to this post

    Hello,

    We managed to reproduce the issue and it seems that there is a bug in the RadListBox control that causes the auto scrolling feature to not work when dragging an item for reordering purposes. We logged the issue in our Public Issue Tracker System where you can track its status.

    I updated your Telerik points for bringing this to our attention. We apologize for any inconvenience that this maybe causing.

    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  11. Bob
    Bob avatar
    7 posts
    Member since:
    Jul 2012

    Posted 14 Aug 2014 Link to this post

    Hello,

    I'm still struggling with Scott's original problem:  RadListBox with working drag/drop intended ONLY for reordering.  Reorder works OK.  But if I drag an item from the RadListBox to another control, it disappears from the listbox.  Have tried several combinations of event handling (including DragLeave and Drop as suggested above), but have not been able to prevent item from disappearing.

    Goal is to prevent drop onto any control except the original RadListBox -- providing for ONLY a reorder of the RadListBox.

    DragLeave doesn't seem to permit cancelling the drag operation overall, and Drop (since it relates to Target) would require implementation for every possible target on the page.

    Can you please describe specifically how to achieve JUST reorder for the RadListBox?

    Thank you
  12. Polya
    Admin
    Polya avatar
    199 posts

    Posted 18 Aug 2014 Link to this post

    Hello Bob,

    In order to prevent dropping on outside of the ListBox you would need to implement a custom ListBoxDragDropBehavior and override the CanDrop method as shown below:
    public override bool CanDrop(DragDropState state)
    {
        if (!state.IsSameControl)
        {
            return false;
        }
      
        return base.CanDrop(state);
    }
    XAML:
    <telerik:RadListBox.DragDropBehavior>
        <local:CustomListBoxDragDropBehavior AllowReorder="True" />
    </telerik:RadListBox.DragDropBehavior>

    Also in order to avoid items removal from the RadListBox we should override the DragDropCompleted method in the custom ListBoxDragDropBehavior:
    public override void DragDropCompleted(DragDropState state)
    {
        if (state.IsSameControl)
        {
            base.DragDropCompleted(state);
        }
    }

    Hopefully this helps.

    Regards,
    Polya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  13. Bob
    Bob avatar
    7 posts
    Member since:
    Jul 2012

    Posted 18 Aug 2014 in reply to Polya Link to this post

    Hello, Polya,

    That works nicely!  Thanks for the guidance.

    Regards,
    Bob
Back to Top
DevCraft banner