Listing Files With CheckBoxes (C# / WinForms)

2019-08-19 13:59发布

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?

5条回答
2楼-- · 2019-08-19 14:38

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

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

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

查看更多
仙女界的扛把子
3楼-- · 2019-08-19 14:41

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.

查看更多
Emotional °昔
4楼-- · 2019-08-19 14:44

The CheckedListBox control would be a good start :)

查看更多
Summer. ? 凉城
5楼-- · 2019-08-19 14:56

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();
checkedListBox1.Items.AddRange(files);
查看更多
贪生不怕死
6楼-- · 2019-08-19 14:58

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

查看更多
登录 后发表回答