Drag and drop files into my listbox

c#

Solution

This code I found here:

private void Form1_Load(object sender, EventArgs e)
{
    listBoxFiles.AllowDrop = true;
    listBoxFiles.DragDrop += listBoxFiles_DragDrop;
    listBoxFiles.DragEnter += listBoxFiles_DragEnter;
}

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

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

Problem

i try to add the option to my application to drag file into my `Listbox` instead of navigate into the file folder and this is what i have try: ``` private void Form1_Load(object sender, EventArgs e) { listBoxFiles.AllowDrop = true; listBoxFiles.DragDrop += listBoxFiles_DragDrop; listBoxFiles.DragEnter += listBoxFiles_DragEnter; } private void listBoxFiles_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; } private void listBoxFiles_DragDrop(object sender, DragEventArgs e) { listBoxFiles.Items.Add(e.Data.ToString()); } ``` but instead of the full file path `e.Data.ToString()` `return System.Windows.Forms.DataObject`

Original source

Related problems