Drag & Drop files to ComboBox

SIMIN

Regular
Joined
Mar 10, 2008
Messages
92
Hello friends,
I have 3 questions about ComboBox, anyone can help me, please? :)

1. Although I have enabled AllowDrop property of ComboBox it does not allow me to drag and drop files into ComboBox. Why?

2. Then should I process incoming files in the _DragDrop event, yes?

3. How can I get the Files.Count to get the number of dropped files?

Thank you very much for helping me :)
 
C#:
        private void comboBox1_DragDrop(object sender, DragEventArgs e)
        {
          string[] names = (string[]) e.Data.GetData(DataFormats.FileDrop);

            comboBox1.Items.AddRange(names);
        }

        private void comboBox1_DragEnter(object sender, DragEventArgs e)
        {
            if(e.Data.GetDataPresent(DataFormats.FileDrop))
             e.Effect = DragDropEffects.Copy;
        }
Should give you the basic idea, the key is to handle the DragEnter and state what effect should be displayed, if this step is missed then the drop event will never be fired.
 
Back
Top