0

lets say im dragging a bunch of files to my list view controll..
how can i filter those files, in a way that when i drop them, i will get only mp3 files
and the rest of the files that i dropped would not show up

2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by vckicks
0

Try checking the filename extension before adding it and only add the ones that end with ".mp3". Here's the full code:

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

private void listview1_DragDrop(object sender, DragEventArgs e)
        {
            string[] directoryName = (string[])e.Data.GetData(DataFormats.FileDrop);

            //Get all the files inside that folder
            string[] files = Directory.GetFiles(directoryName[0]);

            listview1.Items.Clear();

            foreach (string file in files)
            {
                if (Path.GetExtension(file) == ".mp3")
                    listview1.Items.Add(file);
            }
        }

Hope it helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.