Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
I want to use a CheckedListBox in an application where each item in the ListBox is the name of a folder on my hard drive and for the purpose of reading and writing text files to and from each of these folders I want to ensure that multiple item (a folder) can be selected at any time in the CheckedListBox

Thanks for reading :-)
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
            CheckedListBox.CheckedIndexCollection checkedIndices = checkedListBox1.CheckedIndices;
            if (checkedIndices.Count > 0)
                if (checkedIndices[0] != e.Index)
                    checkedListBox1.ItemCheck -= checkedListBox1_ItemCheck;
                    checkedListBox1.SetItemChecked(checkedIndices[0], true);
                    checkedListBox1.ItemCheck += checkedListBox1_ItemCheck;
                    // the user is unchecking the currently checked item, so deselect it...
                    checkedListBox1.SetSelected(e.Index, false);
I can select multiple files but my main question is How to select text files from the directory..
How can I achieve this via code in C#?
Posted 22-Mar-13 3:32am
Edited 22-Mar-13 3:36am
ThePhantomUpvoter at 22-Mar-13 8:35am
What did you try? Did you try the GetFiles method? Maybe Directory.GetFiles(yourfolder, "*.txt")?
sayeed bagban at 22-Mar-13 8:41am
@thePhantomupvoter : Its dynamic,there could be multiple folders to be selected?
ThePhantomUpvoter at 22-Mar-13 8:56am
And so?
sayeed bagban at 22-Mar-13 9:42am
I am just working on this.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this :-
On Selected event:-
string[] filePaths = Directory.GetFiles(@"FolderPath", "*.txt",

Loop through this filePaths array and get file names.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.150302.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100