Click here to Skip to main content
15,889,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Team. I'm having some items inside my list view with check boxes.
I have one radio button outside list view control to select/deselect all check boxes inside list view control.
Thanks in advance for the help!

Below are the Criteria which i want to satisfy:

1.if radio button is fired for the first time, all the check boxes inside list view control should be checked.
2.If any of the check boxes is unchecked manually, clicking the radio button should once again select all the check boxes.
3.If the same radio button is fired again, all the check boxes inside list view control should be unchecked.
3.If any of the check boxes is checked manually, clicking the radio button should once again deselect all the check boxes.

What I have tried:

Was trying to google it, but unfortunately i could not get exactly what i want to satisfy.
Posted
Updated 11-Jul-18 3:59am
v2
Comments
Karthik_Mahalingam 3-Jan-18 1:59am    
using one radio button? how it is possible to check/uncheck the control?
use checkbox instead.

You may try this:

bool isChecked = false;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
    for (int i = 0; i < routeNamesListView.Items.Count; i++)
    {
        if (radioButton1.Checked)
            routeNamesListView.Items[i].Checked = true;
        else
            routeNamesListView.Items[i].Checked = false;
    }
    isChecked = radioButton1.Checked;
}

private void radioButton1_Click(object sender, EventArgs e)
{
    if (radioButton1.Checked && !isChecked)
        radioButton1.Checked = false;
    else
    {
        radioButton1.Checked = true;
        isChecked = false;
    }
}
 
Share this answer
 
Comments
Arvi.S 3-Jan-18 0:46am    
Pradeep. There seems to be no errors but it is not working. I now tell you here that all the check boxes in list view control is checked in default as i use the below code.

routeNamesListView.CheckBoxes = true;
{
for (int i = 0; i < routeNamesListView.Items.Count; i++)
{
routeNamesListView.Items[i].Checked = true;
}
}

Will it be good to select/Deselect check boxes using a single check box? If so kindly let me know
Pradeep Arthanari 3-Jan-18 0:56am    
Pls refer my above code. It has got a radio button to select/deselect all the checkboxes in the list view control.

You need to add a radio button and add the 2 events for the radio button given above (Checkchanged & Click)
Arvi.S 3-Jan-18 1:01am    
Yeah..I did whatever you have coded above. But its not working and throws zero error.
As i mentioned in the above comment, my check boxes comes checked in default which i did not mention in my question. Should i have to change anything from your code?

And in the code which you have sent, if the radio button is clicked once, it is not accepting for the next click action.
Pradeep Arthanari 3-Jan-18 1:28am    
Could you copy your code.
Arvi.S 3-Jan-18 1:31am    
Declared "bool isChecked = false;" globally.

private void t1RadioButton_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < routeNamesListView.Items.Count; i++)
{
if (t1RadioButton.Checked)
routeNamesListView.Items[i].Checked = true;
else
routeNamesListView.Items[i].Checked = false;
}
isChecked = t1RadioButton.Checked;
}

private void t1RadioButton_Click(object sender, EventArgs e)
{
if (t1RadioButton.Checked && !isChecked)
t1RadioButton.Checked = false;
else
{
t1RadioButton.Checked = true;
isChecked = false;
}
}

Once again I'm repeating, all the check boxes in list view control is checked by default!
To deselect specific buttons I used code like below:

RadioButton3.checked:=false;

It works fine in my app.
Hope this helps you.
 
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