如何确定checkedListBox中没有项被选中?

realdrizzt 2010-10-02 02:40:52
我在ItemCheck事件中是这么写得
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
CheckedListBox clb = (CheckedListBox)sender;
for (int x = 0; x != checkedListBox1.CheckedItems.Count ; x++)
{
if (x != 0)
{
clb.Tag = true;
}
else
{
clb.Tag = false;
}
}
ValidateOK();
但是经过试验,必须选中三个以上的项目才能验证,到底是怎么回事呀
...全文
459 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
realdrizzt 2010-10-06
  • 打赏
  • 举报
回复
我确实是检查checkedListBox1.CheckedItems.Count的值是否为空了,请看代码,但是就是不能确定checkedListBox中的项是否全部没有选中。
kensouterry 2010-10-03
  • 打赏
  • 举报
回复
如果楼主要确定没有项被选中只需要检查listChecked.Count是否为0即可。为0,则没有项被选中了。
kensouterry 2010-10-03
  • 打赏
  • 举报
回复
不知道楼主是不是这个意思!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

//add 3 items to collection checkedListBox
//and make sure one item is chosen,
checkedListBox1.Items.Add("KDS",true);
checkedListBox1.Items.Add("2");
checkedListBox1.Items.Add("3");

//listChecked就是处于选中状态的所有item集合
CheckedListBox.CheckedItemCollection listChecked = checkedListBox1.CheckedItems;

for (int i = 0; i < listChecked.Count; i++)
{
//将被选中item的text打印出来
MessageBox.Show("{0}", listChecked[0].ToString());

}
}
}

}
qq100191677 2010-10-02
  • 打赏
  • 举报
回复

for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
BaseParser cli = null;
switch (checkedListBox1.GetItemText(checkedListBox1.Items[i]))
{
case "ssw":
cli = new Soso();
bplist.Add(cli);
break;
case "ww":
cli = new Wenwen();
bplist.Add(cli);
break;
case "ss":
cli = new SosoBlog();
bplist.Add(cli);
break;
case "sa":
cli = new Sogou();
bplist.Add(cli);
break;
case "a":
cli = new _1688();
bplist.Add(cli);
break;
case "q":
cli = new Xywy();
bplist.Add(cli);
break;
default:
break;
}
}
}
wuyq11 2010-10-02
  • 打赏
  • 举报
回复
private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if(e.NewValue==CheckState.Checked)
{}
}

string s=String.Empty;
for (i = 0; i <=checkedListBox1.Items.Count-1; i++)
{
if(checkedListBox1.GetItemChecked(i))
{
s = checkedListBox1.Items[i].Value+",";
}
}
foreach(object item in checkedListBox1.Items) {
}

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧