Solved

SelectionMode on a CheckedListBox

Posted on 2004-10-14
3
384 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
Comment Utility
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
Comment Utility
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
Comment Utility
If you want only one item to be checked, I suggest you to use radio buttons..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

15 Experts available now in Live!

Get 1:1 Help Now