开发者

Populating checkedListBox using c# windows application

开发者 https://www.devze.com 2023-01-19 06:10 出处:网络
I want to populate the checkedListBox control with file names from a directory which i can do now using the following code.

I want to populate the checkedListBox control with file names from a directory which i can do now using the following code.

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(txtPath.Text.ToString());
System.IO.FileSystemInfo[] files = di.GetFileSystemInfos();
checkedListBox1.Items.AddRange(files);

But when the checkbox is selected, i want to get the pat开发者_StackOverflow社区h of file name. How can i do this ?


Use the SelectedIndexChanged event of the checkbox item to see which item was checked, and pull the path down from the event args passed into the event handler.

You can then use ((System.IO.FileSystemInfo)checkedListBox1.SelectedItem).FullName; to get the full file path and name. And if needed, you can use regex to extract the path from the filename.

You can find multiple paths using the SelectedIndices property of the checkedListBox control.

0

精彩评论

暂无评论...
验证码 换一张
取 消