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

Drag and drop multiple listbox rows

1 Answer 205 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.
MNP
Top achievements
Rank 1
MNP asked on 25 Aug 2009, 04:19 PM
The example posted here

http://www.telerik.com/community/forums/winforms/ui-controls/drop-and-drag-between-two-listbox.aspx

only allows single listboxitem moves. If I set the mousedown event to be

 Private Sub lstMembers_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles lstMembers.MouseDown 
      Dim lstBox As RadListBox = sender 
      lstBox.DoDragDrop(lstBox.SelectedItems, DragDropEffects.Move) 
   End Sub 




The listbox does not select the proper values.

Is there a way you can drag multiple values?

Thanks

-Matt

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 25 Aug 2009, 09:40 PM
Matt,

I've take the example and modified it to support multi-drag drop functionality:

        bool isMouseDown = false
        bool isDragAndDrop = false
        private void radListBox1_MouseDown(object sender, MouseEventArgs e) 
        { 
            isMouseDown = true
        } 
 
        private void radListBox1_MouseMove(object sender, MouseEventArgs e) 
        { 
            if (!isMouseDown || isDragAndDrop) return
 
            RadListBox listBox = sender as RadListBox; 
            listBox.DoDragDrop(listBox.SelectedItems.ToList(), DragDropEffects.Copy); 
 
            isDragAndDrop = true
        } 
 
        private void radListBox1_MouseUp(object sender, MouseEventArgs e) 
        { 
            isMouseDown = false
            isDragAndDrop = false
        } 
 
        private void radListBox1_DragOver(object sender, DragEventArgs e) 
        { 
            e.Effect = DragDropEffects.Copy;  
        } 
 
        private void radListBox1_DragDrop(object sender, DragEventArgs e) 
        { 
            RadListBox listBox = sender as RadListBox; 
 
            List<RadItem> items = (List<RadItem>)e.Data.GetData(typeof(List<RadItem>)); 
            RadListBox sourceListBox = items[0].ElementTree.Control as RadListBox; 
 
            foreach (RadItem lstBoxItem in items) 
            { 
                sourceListBox.Items.Remove(lstBoxItem); 
                listBox.Items.Add(lstBoxItem); 
            } 
        } 

I subscribed to the same events on both listboxes.

- Robert



Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
MNP
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or