Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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 :-)


C#
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;
                }
                else
                {
                    // 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
Updated 22-Mar-13 2:36am
v2
Comments
[no name] 22-Mar-13 8:35am    
What did you try? Did you try the GetFiles method? Maybe Directory.GetFiles(yourfolder, "*.txt")?
sayeed bagban 22-Mar-13 8:41am    
@thePhantomupvoter : Its dynamic,there could be multiple folders to be selected?
[no name] 22-Mar-13 8:56am    
And so?
sayeed bagban 22-Mar-13 9:42am    
I am just working on this.

1 solution

Try this :-

On Selected event:-

C#
string[] filePaths = Directory.GetFiles(@"FolderPath", "*.txt",
                                         SearchOption.AllDirectories);



Loop through this filePaths array and get file names.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900