Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a form containing radio buttons
(button 1----> ISSUED) and
(button 2----> NON_ISSUED

and i have a checked list box which will contain certain items.
i need to enable the user to check multiple items in checked list box only if radio button 1 is checked.
else if radiobutton2 is checked i want to restrict selection mode to SINGLE selection mode.
is it possible??
thanks in advance to those who are interested to help :)
Posted

Why not have 2 sets of list controls, a checkbox list for 1 and a radio button list for 2. If button 1 is selected, hide the radio button list and show checkbox list, else, the other way around.

[Edit]
OK, so 2 controls will not work. Try this then. Let me know if it works for you.
C#
private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
                }
                checkedListBox1.SetItemCheckState(checkedListBox1.SelectedIndex, CheckState.Checked);
            }
        }

[/Edit]
 
Share this answer
 
v2
Comments
greatreddevil 11-Aug-11 2:36am    
That's a pretty smart idea. but think it can be done with a single listbox.... :)
lets hope i can come up with the solution.
THANKS for trying to help BTW.. :)
walterhevedeich 11-Aug-11 3:28am    
I have updated my answer. Have a look.
shreya1987 11-Aug-11 2:41am    
It's good idea, having 2 set's of conrols. BUT it will affect code performance as both control list need to be load each time Whether they are used or not
Unfortunately, for CheckedListBox objects, multiple selection is not supported. You can set the mode to one item or no items.

Read this link for more info.

http://social.msdn.microsoft.com/Forums/en-US/vbbugsubmissionpilot/thread/1a4acbfe-8e1b-42a3-ac27-1ed280d8a9af/[^]
 
Share this answer
 
v2
Comments
greatreddevil 11-Aug-11 3:17am    
i have tried a same but its not working as expected.... :(
i get an error that checkedlistbox does not support multipisimple or multiextended selection mode
Toniyo Jackson 11-Aug-11 3:32am    
See my updated answer
Multiple selection is not supported in checkedlistbox. But toggling CheckOnClick = true on one radio button click and false on second radio button click could help.

C#
if (RadioButton1.Checked) 
    checkedListBox1.CheckOnClick =true;
else
   checkedListBox1.CheckOnClick = false;


It's not the solution you want, but could make your multiple selection easier.
 
Share this answer
 
C#
if (RadioButton1.Checked) 
    ListBox1.SelectionMode = SelectionMode.MultiExtended;
else
    ListBox1.SelectionMode = SelectionMode.One;
endif
 
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