使用一个单选按钮选择/取消选择列表视图中的所有复选框 [英] Select/deselect all checkboxes in listview using one radio button

查看:128
本文介绍了使用一个单选按钮选择/取消选择列表视图中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿团队。我的列表视图中有一些项目带有复选框。

我在列表视图控件外有一个单选按钮,用于选择/取消选择列表视图控件中的所有复选框。

提前感谢您的帮助!



以下是我想要满足的标准:



1.如果第一次触发单选按钮,则应检查列表视图控件中的所有复选框。

2.如果未选中任何复选框,请单击单选按钮再次选中所有复选框。

3.如果再次触发相同的单选按钮,则应取消选中列表视图控件中的所有复选框。

3.如果有的话手动检查复选框,单击单选按钮应再次取消选中所有复选框。



我尝试过:



试图谷歌它,但不幸的是我无法得到我想要满足的。

解决方案

你可以试试这个:



 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;
}
}


要取消选择特定按钮,我使用如下代码:



RadioButton3.checked:= false;



它在我的应用程序中工作正常。

希望这可以帮到你

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.

解决方案

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;
    }
}


To deselect specific buttons I used code like below:

RadioButton3.checked:=false;

It works fine in my app.
Hope this helps you.


这篇关于使用一个单选按钮选择/取消选择列表视图中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆