Showing posts with label Windows Forms. Show all posts
Showing posts with label Windows Forms. Show all posts

Friday, October 12, 2012

Drag And Drop Functionality for ListBox

This code implements drag and drop functionality to listbox

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            e.Effects = DragDropEffects.Copy;
        }

        private void listBox1_Drop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                listBox1.Items.Add(file);
            }
        }