Click here to Skip to main content
15,868,016 members

CheckedListBox - How to select the text file from directory from checklistbox

sayeed bagban asked:

Open original thread
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#?
Tags: C#, Windows, Windows Forms, Checkbox

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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