簡體   English   中英

使用C#Windows應用程序填充checkedListBox

[英]Populating checkedListBox using c# windows application

我想用目錄中的文件名填充checkedListBox控件,現在我可以使用以下代碼進行操作。

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

但是,當選中該復選框時,我想獲取文件名的路徑。 我怎樣才能做到這一點 ?

使用復選框項目的SelectedIndexChanged事件來查看選中了哪個項目,然后從傳遞到事件處理程序的事件args中拉下路徑。

然后可以使用((System.IO.FileSystemInfo)checkedListBox1.SelectedItem).FullName; 獲取完整的文件路徑和名稱。 並且,如果需要,您可以使用正則表達式從文件名中提取路徑。

您可以使用checkedListBox控件的SelectedIndices屬性找到多個路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM