List files using CheckBoxes (C # / WinForms)

I want to list the files in a directory and put a checkbox next to each one, so I can select some of them and perform operations on each selected file, what's the best way to do this?

0
list c # file winforms


source to share


5 answers


Drop a CheckedListBox into the form, then fill that content using the DirectoryInfo and FileSystemInfo classes, for example:



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

      

+6


source to share


You can use the checklist control that is built into the winforms control (see links below):

http://www.functionx.com/vcsharp/controls/checkedlistbox1.htm



http://msdn.microsoft.com/en-us/library/3ss05xx6.aspx

+2


source to share


CheckedListBox

would be a good start :)

+2


source to share


You can also use the OpenFileDialog class. This will display the standard Windows file open dialog and you can configure it to select multiple files.

In many cases, using the standard dialog can be easier for the user than using the 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 a dialog to the form constructor and set its properties there.

+1


source to share


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

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics