What I want to do is a drop down list (comboBox) that the user can see only selected files. For example, if user selects a Word Documents from a comboBox, on the explorer will be only visible a doc files.
I have done a FileFilter class:

public class FileFilter
{
    public FileFilter(string name, string filter)
    {
        // Store values
        Name = name;
        Filter = filter;
    }
    public string Name { get; private set; }
    public string Filter { get; private set; }
}

and on the Form1 load I specified the filter available:

Collection<FileFilter> filters = new Collection<FileFilter>();
filters.Add(new FileFilter("Word Documents", "*.doc"));
filters.Add(new FileFilter("Pdf Documents", "*.pdf"));

Now I would like to know how can I fill the comboBox with the Collection of FileFilter objects (with "Word Documents" and "Pdf Documents", and then use the filter on Directory.GetFiles();

If I do on the form_Load:

comboBox1.Items.Add(filter);

it doesn`t show what I want in the comboBox.

Edited 7 Years Ago by Mitja Bonca: n/a

Adding

comboBox1.DisplayMember = "Name"; 
comboBox1.ValueMember = "Filter";

should show what you want to see, then later you should be able to

Directory.GetFiles(comboBox1.SelectedValue);

(or something similar) later.

The 1st works :) I got the litems into comboBox!
2nd doesn`t, I changed this to:

Directory.GetFiles(comboBox1.SelectedValue.ToString());

But its still not working. Where exactly do I need to put it?

I am doing somekind of an windows explorer, which shows directories and files. Do I put it into the code where the files are added into listView?

Yeah, most likely (unless you are adding full path info) you are getting a list of matching files in your bin\debug directory. Try adding a folder where you know some of those files are to the GetFiles like this:

Directory.GetFiles("C:\\test folder\\" + comboBox1.SelectedValue.ToString());

While you are testing, you might want to add a 3rd item "All Files", "*.*" which might help you figure out which folder you are searching. Eventually, you might add a FolderBrowserDialog to help your user change which folder you are searching.

in comboBox even I have:

string myPath = treeView1.SelectedNode.FullPath;
Directory.GetFiles(myPath, comboBox1.SelectedValue.ToString());

and all works fine. I got the path into myPath, and in comboBox1.selectedItem is the FileFilter ("*.doc" in my case).
But it`s not showing the filtered files!!

Maybe is the problem that I need to specify that the files need to show up in the listView. I haven`t specified that in the upper code.

Edited 7 Years Ago by Mitja Bonca: n/a

Is this SOLVED? If so, please mark as SOLVED, otherwise please restate the current problem. Thanks.

This question has already been answered. Start a new discussion instead.