RadListBox drag-n-drop limited amount of items

2 posts, 0 answers
  1. Kirill
    Kirill avatar
    1 posts
    Member since:
    Mar 2014

    Posted 02 Mar 2014 Link to this post

    Hi there. I've met the following challenge with RadListBox (RLB) control. I need to implement Drag-n-Drop feature beetween two RLBs, where the destination RLB must contain up to 6 elements and they must be reordable. I used DragDropEffects property in proper condition using, it works OK for me, but if I add all 6 items to the destination RLB I cannot reorder them, meanwhile RLB with up to 5 items is reordable. Could you please assist with it? Thanks in an advance.
  2. Kalin
    Kalin avatar
    1360 posts

    Posted 05 Mar 2014 Link to this post

    Hello Kirill,

    You probably couldn't reorder items because the drop is disabled when the items count is six. This also prevents the drop when reordering the items. I can suggest you an approach using a custom ListBoxDragDropBeahavior which also check is if the dragging has started from the same control. You will need to override the CanDrop method the following way:

    public class CustomListBoxDragDropBehavior : ListBoxDragDropBehavior
        public override bool CanDrop(DragDropState state)
            if (state.DestinationItemsSource.Count > 5 && !state.IsSameControl)
                return false;
            return base.CanDrop(state);

    The XAML should look the following way:

        <Style TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
    <Grid x:Name="LayoutRoot" Background="White">
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="150" />           
        <telerik:RadListBox Grid.Column="0" AllowDrop="True" ItemsSource="{Binding ItemsSource1}" Margin="10">
                <local:CustomListBoxDragDropBehavior />
        <telerik:RadListBox Grid.Column="1" AllowDrop="True" ItemsSource="{Binding ItemsSource2}" Margin="10">
                <local:CustomListBoxDragDropBehavior />

    Hope this helps.


    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Back to Top