当复选框“全部选中”时,我试图选择复选框列表中的所有项目”
如何获得,这是我的代码
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (cbAll.Checked)
{
if(clbViruslist.Items.Count > 0)
{
// here clbViruslist is the checked list o
// for(int i=0;i<clbViruslist.Items.Count;i++)
// clbViruslist.SetSelected(i,true);
// clbViruslist.SetSelected(0,true ) ;
}
}
}
最佳答案
private void cbAll_CheckedChanged(object sender, EventArgs e)
{
if (cbAll.Checked)
{
foreach (ListItem item in clbViruslist.Items)
{
item.Selected = true;
}
}
}
或者这更好
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (ListItem item in clbViruslist.Items)
{
item.Selected = checkBox1.Checked;
}
}
关于c# - 试图在单击单个复选框时在选中的列表框中选择所有项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12672030/