tags:

views:

600

answers:

2

I want to select all the items in listbox. Here iam using listbox1.selectAll() for selecting all items. And for Deselecting all items in a listbox iam using listbox1.selecteditems.clear(). thats working perfectly

Now i want to do validations like if i select all items by using listbox1.selectAll() and then if i select one item in listbox all selected items selection is going off and the radio button still showing the selectall is checked.But i dont have all items selected in a listbox. How to do that. Any suggestion plz.

A: 

You could implement a check in the ListBox1_SelectedIndexChanged event to do a check against the checkbox i.e.

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     myCheckBox.Checked = listBox1.SelectedItems.Count > 1;
}
James
For Radio button what should i use. I want to do validations for listboxitems having radio buttons. If i select all the items by using selectall then if i select an listbox item the selection is going off. what to do for this behaviour.
ibrahimkhan
Oh sorry, it should be the same property of a radio button i.e. myRadioButton.Checked.
James
This is of course assuming that you have selected "Select All" radio button and you then select a specific item in the list (and the others are being deselected). If you put the above code in the SelectedItemChanged event then whenver the index changes, it will check that you have multiple items selected and set the checked state of the radio button accordingly.
James
+1  A: 

I would suggest using a single CheckBox or two standard Buttons instead of RadioButtons.

If some but not all or none of the items are selected, which RadioButton will you check? It doesn't make sense to have a "Some selected" RadioButton.

With buttons, you simply select/unselect all of the items when the button is pressed.

With a single CheckBox, you can use the three state feature to set the CheckBox as follows: checked = all selected; third state = some selected; unchecked = none selected.

Handle the appropriate Checked and Unchecked handlers on the CheckBox for updating the ListBox, and respond to the ListBox.SelectionChanged event to update the CheckBox in response to manual selection changes.

Josh G
I got the sloution. Iam using Buttons Instead of RadioButtons.Thanks for the solution.
ibrahimkhan
RadioButtons are meant to allow 0 or 1 selections in a list. Checkboxes allow for 0:number selections of the list.
monksy