Drop and drag between two listbox

Thread is closed for posting
4 posts, 0 answers
  1. Markus
    Markus avatar
    9 posts
    Member since:
    Nov 2008

    Posted 29 Jan 2009 Link to this post

    I read this

    in 2007 it was not supported, does radlistbox support it now in 2009?

    Or is there some workaround code avaible for that function.
  2. Boyko Markov
    Boyko Markov avatar
    610 posts

    Posted 30 Jan 2009 Link to this post

    Hi Markus,

    Thank you for the questions.

    Please follow the steps:

    1. Create two RadListBox controls.
    2. Add some RadListBoxItem instances to the controls.
    3. Set the AllowDrop property to true for the both of the listboxes.
    4. Subscribe to MouseDown, DragOver and DragDrop events.
    5. Please see the sample code below for the event handlers:

    private void radListBox_DragDrop(object sender, DragEventArgs e) 
                RadListBox listBox = sender as RadListBox; 
                RadListBoxItem item = (RadListBoxItem)e.Data.GetData(typeof(RadListBoxItem)); 
                RadListBox sourceListBox = item.ElementTree.Control as RadListBox; 
            private void radListBox_MouseDown(object sender, MouseEventArgs e) 
                RadListBox listBox = sender as RadListBox; 
                if (listBox.SelectedIndex >= 0) 
                    listBox.DoDragDrop(listBox.Items[listBox.SelectedIndex], DragDropEffects.Copy); 
            private void radListBox_DragOver(object sender, DragEventArgs e) 
                e.Effect = DragDropEffects.Copy; 

    I hope this helps. Please contact me again if I can help you with something else.

    Sincerely yours,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Joshua Gates
    Joshua Gates avatar
    72 posts
    Member since:
    Feb 2007

    Posted 24 Feb 2009 Link to this post

    i have implented the code suggested...
    however when i do..it does not select the item i want...
    it always selects the first item..
    basically the item selected does not highlight...
    but if i comment out the code in the mousedown event...it highlights the item correctly but does not drag the item
  4. Martin Vasilev
    Martin Vasilev avatar
    1061 posts

    Posted 27 Feb 2009 Link to this post

    Hi Joshua Gates,

    Thank you for writing. I have prepared a complete sample project demonstrating how to implement drag and drop between two RadListBoxes. Please, find it as an attachment to this message.

    Hope this helps, write me back if you still have more questions.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top