C# CheckedListBox控件的使用方法
作者:互联网
checkedListBox1.DataSource = dt;
checkedListBox1.DisplayMember = "item";
checkedListBox1.ValueMember = "code";
推断第i项是否选中,选中为true,否则为false
if(checkedListBox1.GetItemChecked(i))
{
return true;
}
else
{
return false;
}
设置第i项是否选中
checkedListBox1.SetItemChecked(i, true); //true改为false为没有选中。
全选 勾选取消
checkbox1 控件
for (int j = 0; j < checkedListBox1.Items.Count; j++)
checkedListBox1.SetItemChecked(j, checkbox1.checked);
}
获取选中的值
if (checkedListBox1.GetItemChecked(i))
{
strCollected = checkedListBox1.GetItemText(
checkedListBox1.Items[i]);
}
设置CheckedListBox中第i项的Checked状态
checkedListBox1.SetItemCheckState(i, CheckState.Checked);
checkedListBox 单选设置(代码实现)
private void chkl_ItemAuditing_ItemCheck(object sender,
ItemCheckEventArgs e)
{
if (chkl_ItemAuditing.CheckedItems.Count > 0)
{
for (int i = 0; i < chkl_ItemAuditing.Items.Count; i++)
{
if (i != e.Index)
{
this.chkl_ItemAuditing.SetItemCheckState(i,
System.Windows.Forms.CheckState.Unchecked);
}
}
}
}
标签:控件,ItemAuditing,false,C#,checkedListBox1,chkl,选中,CheckedListBox,true 来源: https://blog.csdn.net/qq_36248777/article/details/98945912