Keep dragged/dropped item in listbox selected

4 posts, 0 answers
  1. Jeroen
    Jeroen avatar
    49 posts
    Member since:
    Feb 2012

    Posted 26 Jun 2013 Link to this post

    Hi,

    I'm trying to figure out which event is fired when you drag and drop an item within the same listbox?

    The actual problem I have is that when I drop my item in the same listbox (I only want to support reordering items in the listbox), the selected item automatically becomes unselected. I want the item that I just dropped to STAY selected. I can't find any property that causes that behaviour, and I can't find any event in which I can handle this myself.

    I've tried DragDropManager.AddDragDropCompletedHandler(), DragDropManager.AddDropHandler(), the Drop event... Nothing seems to work.

    How should I approach this?

    Kind regards,
    -- Jeroen
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 27 Jun 2013 Link to this post

    Hi Jeron,

    Usually this would be done in the Drop handler. However, if you are using the ListBoxDragDropBehavior, you have to subscribe to the drop event with handledEventsToo set to true.

    Let me know if that helps! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Jeroen
    Jeroen avatar
    49 posts
    Member since:
    Feb 2012

    Posted 28 Jun 2013 Link to this post

    How do I do that? I'm guessing using AddHandler in code behind, but I can't seem to figure out how to subscribe a DropEvent that way. I'm working in C#.

    My listbox is defined as follows:

    <telerik:RadListBox ItemsSource="{Binding BitmapComponentModel.ListLayers}" x:Name="LbLayers" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                        ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="2"
                                        Style="{StaticResource RadListBoxStyle}"
                                        SelectedItem="{Binding BitmapComponentModel.SelectedLayer, Mode=TwoWay}" SelectionChanged="LbLayers_SelectionChanged"
                                        SelectionMode="Single"
                                        Background="Black">
                        <telerik:RadListBox.DragVisualProvider>
                            <telerik:ScreenshotDragVisualProvider />
                        </telerik:RadListBox.DragVisualProvider>
                        <telerik:RadListBox.DragDropBehavior>
                            <telerik:ListBoxDragDropBehavior AllowReorder="True"/>
                        </telerik:RadListBox.DragDropBehavior>
                        <telerik:RadListBox.ItemTemplate>
                            <DataTemplate>
                                <!-- ... -->
                            </DataTemplate>
                        </telerik:RadListBox.ItemTemplate>
                    </telerik:RadListBox>
  5. Jeroen
    Jeroen avatar
    49 posts
    Member since:
    Feb 2012

    Posted 02 Jul 2013 Link to this post

    I figured it out...

    DragDropManager.AddDropHandler(LbLayers, OnElementDrop, true);

    That seems to work. Thanks!
Back to Top