11 Answers, 1 is accepted
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
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
>
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.
George
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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
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.
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
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.
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
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);
}
<
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
That works nicely! Thanks for the guidance.
Regards,
Bob