Solved

SelectionMode on a CheckedListBox

Posted on 2004-10-14
3
385 Views
Last Modified: 2009-07-29
The SelectionMode.One on a Checked List Box DOES NOT WORK! I've read the MSDN Instructions, and it does nothing. You can still select as many check boxes as you want ..anyone have a workaround for this?
0
Comment
Question by:derekthornton
3 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12312012
SelectoinMode is something else. In a checked list box you can CHECK the items and also SELECT the items. The SelectionMode says that only one item can be selected, but multiple can be checked.

You can use the ItemCheck event to manually disable multiple checks. The event is described here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscheckedlistboxclassitemchecktopic.asp
0
 
LVL 3

Accepted Solution

by:
aacool earned 500 total points
ID: 12312978
Here is code that solves your problem:

private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
   SelectionMode mode = checkedListBox1.SelectionMode;
  if(mode == SelectionMode.One)
 {
    //uncheck all other items
    foreach(int i in checkedListBox1.CheckedIndices)
   {
      if(i!=e.Index)
      {
                checkedListBox1.SetItemCheckState(i,CheckState.Unchecked);            
      }
   }
}
                        
            }
0
 
LVL 1

Expert Comment

by:Kahhoe
ID: 12315793
If you want only one item to be checked, I suggest you to use radio buttons..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different Delete Messages 7 37
ASP.NET Web API or ASP.NET Core MVC? 3 52
System.Speech 2 16
User Authentication using Digital Certificate 2 26
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now