Listing Files With CheckBoxes (C# / WinForms)

I want a way to list files in a directory and putting a check box beside each one of them so I can select some of them and perform operations with each selected file, what's the best way to do this?


Drop a CheckedListBox control onto the form, then populate the contents using the DirectoryInfo and FileSystemInfo classes, like this:

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("c:\\");
System.IO.FileSystemInfo[] files = di.GetFileSystemInfos();

You can use checked list box control which is built-in winforms control (see links below):

The CheckedListBox control would be a good start :)

You can also use the OpenFileDialog class. This will display the standard windows open file dialog and you can set it to allow selection of multiple files.

In many cases using a standard dialog can be easier for the user than using your custom user interface.

Try something like this:

OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.InitialDirectory =@"C:\temp\";
fileDialog.Multiselect = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
  string[] files = fileDialog.FileNames;

Or you can add the dialog in the forms designer and set its properties there.

Check out FileView Control It can show files/folders with check boxes.

Need Your Help

Loading an external font via inline CSS

html css fonts inline font-face

Is it possible to load an external font via inline CSS?

Custom list view with check box in android

java android android-listview nullpointerexception android-custom-view

I am trying to add check box in customized list view but it is giving error of NullPointerException.