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

Drop and drag between two listbox

3 Answers 163 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Markus
Top achievements
Rank 1
Markus asked on 29 Jan 2009, 02:02 PM
I read this
http://www.telerik.com/community/forums/winforms/ui-controls/drag-drop.aspx

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


Or is there some workaround code avaible for that function.

3 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 30 Jan 2009, 12:42 PM
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; 
            sourceListBox.Items.Remove(item); 
            listBox.Items.Add(item); 
        } 
        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.
0
Joshua Gates
Top achievements
Rank 1
answered on 24 Feb 2009, 04:10 PM
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
0
Martin Vasilev
Telerik team
answered on 27 Feb 2009, 12:42 PM
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.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Markus
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Joshua Gates
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or