This is a migrated thread and some comments may be shown as answers.

Drag Drop Problem

11 Answers 136 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Scott Rakestraw
Top achievements
Rank 1
Scott Rakestraw asked on 10 Jul 2012, 11:10 PM
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.

11 Answers, 1 is accepted

Sort by
0
Lancelot
Top achievements
Rank 1
answered on 11 Jul 2012, 09:05 PM
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
0
Scott Rakestraw
Top achievements
Rank 1
answered on 12 Jul 2012, 02:35 PM
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>
0
Scott Rakestraw
Top achievements
Rank 1
answered on 12 Jul 2012, 02:57 PM
Is there no way to scroll the listbox while you are dragging?  I can't seem to make that work either.
0
George
Telerik team
answered on 16 Jul 2012, 04:47 PM
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.

0
Bala
Top achievements
Rank 1
answered on 19 Jul 2012, 09:53 AM
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
0
Vladi
Telerik team
answered on 24 Jul 2012, 11:55 AM
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.

0
Manoj
Top achievements
Rank 1
answered on 07 Jun 2013, 11:50 AM
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
0
Vladi
Telerik team
answered on 10 Jun 2013, 03:23 PM
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.

0
Bob
Top achievements
Rank 1
answered on 14 Aug 2014, 01:05 PM
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
0
Polya
Telerik team
answered on 18 Aug 2014, 09:02 AM
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.
 
0
Bob
Top achievements
Rank 1
answered on 18 Aug 2014, 09:12 PM
Hello, Polya,

That works nicely!  Thanks for the guidance.

Regards,
Bob
Tags
ListBox
Asked by
Scott Rakestraw
Top achievements
Rank 1
Answers by
Lancelot
Top achievements
Rank 1
Scott Rakestraw
Top achievements
Rank 1
George
Telerik team
Bala
Top achievements
Rank 1
Vladi
Telerik team
Manoj
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Polya
Telerik team
Share this question
or