CheckedListBox 怎么让它单选
2个回答
展开全部
方法一:
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (i != e.Index) // 不是单击的项
{
//checkedListBox1.SetItemChecked(i,false); 这一句也可以
checkedListBox1.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); //设置单选核心代码
}
}
string SelectedValue = checkedListBox1.Items[e.Index].ToString().Trim();//获取选定的值
}
方法二:
for (int i = 0; i < checkedListBox1.CheckedIndices.Count; i++)
{
if (checkedListBox1.CheckedIndices[i] != e.Index)
{
//checkedListBox1.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked);
checkedListBox1.SetItemChecked(checkedListBox1.CheckedIndices[i], false);
}
string SelectedValue = checkedListBox1.Items[e.Index].ToString().Trim();//获取选定的值
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (i != e.Index) // 不是单击的项
{
//checkedListBox1.SetItemChecked(i,false); 这一句也可以
checkedListBox1.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked); //设置单选核心代码
}
}
string SelectedValue = checkedListBox1.Items[e.Index].ToString().Trim();//获取选定的值
}
方法二:
for (int i = 0; i < checkedListBox1.CheckedIndices.Count; i++)
{
if (checkedListBox1.CheckedIndices[i] != e.Index)
{
//checkedListBox1.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked);
checkedListBox1.SetItemChecked(checkedListBox1.CheckedIndices[i], false);
}
string SelectedValue = checkedListBox1.Items[e.Index].ToString().Trim();//获取选定的值
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void checkedListBoxControl1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBoxControl1.ItemCount; i++)
{
checkedListBoxControl1.SetItemCheckState(i, CheckState.Unchecked);
}
}
so easy!
{
for (int i = 0; i < checkedListBoxControl1.ItemCount; i++)
{
checkedListBoxControl1.SetItemCheckState(i, CheckState.Unchecked);
}
}
so easy!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询