checkedListBox的使用
.
添加项
checkedListBox1.Items.Add("蓝色");
checkedListBox1.Items.Add("红色");
checkedListBox1.Items.Add("黄色");
.
判断第i项是否选中,选中为true,否则为false
if(checkedListBox1.GetItemChecked(i))
{
return true;
}
else
{
return false;
}
.
设置第i项是否选中
checkedListBox1.SetItemChecked(i, true); //true改为false为没有选中。
.
设置全选
添加一个名为select_all的checkbox控件,由其控制checkedListBox是全选还是全不选。
private void select_all_CheckedChanged(object sender, EventArgs e)
{
if(select_all.Checked)
{
for (int j = ; j < checkedListBox1.Items.Count; j++)
checkedListBox1.SetItemChecked(j, true);
}
else
{
for (int j =; j < checkedListBox1.Items.Count; j++)
checkedListBox1.SetItemChecked(j, false);
}
}
.
得到全部选中的值 ,并将选中的项的文本组合成为一个字符串。
string strCollected = string.Empty;
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
if (strCollected == string.Empty)
{
strCollected = checkedListBox1.GetItemText(
checkedListBox1.Items[i]);
}
else
{
strCollected = strCollected + "/" + checkedListBox1.
GetItemText(checkedListBox1.Items[i]);
}
}
}
.
设置CheckedListBox中第i项的Checked状态
checkedListBox1.SetItemCheckState(i, CheckState.Checked);
.
private void checkBoxAll_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxAll.Checked)
{
//被选择了则将CheckedListBox中的所有条目都变为Checked状态
for (int i = ; i < checkedListBoxLayerControl.Items.Count;
i++)
{
checkedListBoxLayerControl.SetItemCheckState(i,
CheckState.Checked);
}
}
else
{
//否则变成Unchecked状态
for (int i = ;
i < checkedListBoxLayerControl.Items.Count; i++)
{
checkedListBoxLayerControl.SetItemCheckState(i, CheckState.Unchecked);
}
}
}
.
checkedListBox 单选设置(代码实现)
private void chkl_ItemAuditing_ItemCheck(object sender,
ItemCheckEventArgs e)
{
if (chkl_ItemAuditing.CheckedItems.Count > )
{
for (int i = ; i < chkl_ItemAuditing.Items.Count; i++)
{
if (i != e.Index)
{
this.chkl_ItemAuditing.SetItemCheckState(i,
System.Windows.Forms.CheckState.Unchecked);
}
}
}
}
.
checkedListBox1显示一个数据库中关键字对应的所有记录
for (int i = ; i < table.Rows.Count; i++)
{
string name = table.Rows["myname"].ToString();
string paw = table.Rows["mypaw"].ToString();
checkedListBox1.Items.Add(name + paw);
}
.
for(i=;i<CheckedListBox.Items.Count;i++)
{
if(CheckedListBox.GetItemText(
CheckedListBox.Items)=="你得到的值")
{
CheckedListBox.SetItemChecked(i,true);
}
}
.
清除checkedListBox1中所有的选项
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.Items.Clear();
}
.
//设置索引为index的项为选中状态
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, true);
}
.
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetSelected(i))
{
MessageBox.Show(checkedListBox1.CheckedItems.ToString());
}
}
.
//选中checkedListBox1所有的选项
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemCheckState(i, CheckState.Checked);
}
.
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
//如果checkedListBox1的第i项被选中,
//则显示checkedListBox1对应的值
if (checkedListBox1.GetItemChecked(i))
{
MessageBox.Show(checkedListBox1.Items.ToString());
}
}
.
//反向选择checkedListBox1的选项
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
checkedListBox1.SetItemChecked(i, false);
}
else
{
checkedListBox1.SetItemChecked(i, true);
}
}
.
//checkedListBox1中选定的项->checkedListBox2
for (int i = ; i < checkedListBox1.CheckedItems.Count; i++)
{
checkedListBox2.Items.Add(this.checkedListBox1.CheckedItems);
//remove是除去一个具体的值,不是index,注意了
this.checkedListBox1.Items.Remove(
this.checkedListBox1.CheckedItems);
}
.
CheckedlistBox控件比较有用到两个属性分别为CheckOnClick为True:表示单击就选中当前行,为False:要点两下才可以选中。(默认值为False)。还有一个属性为ThreeDCheckBoxes为True:表示三维的选中标记,为False:表示表面的显示标记。(默认值为False)。
.
for (int i = ; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
checkedListBox1.SelectedIndex = i;//利用SelectedValue取得Value值时,只能取得当前焦点项的值。所以要对整个CheckedListBox中的所有勾选项,让其都做一次焦点项才能取得所有勾选的项的值。
str+= checkedListBox1.SelectedValue;
}
}
.绑定数据
checkedListBox1.DataSource = dt;
checkedListBox1.DisplayMember = "item";
checkedListBox1.ValueMember = "code";
checkedListBox的使用的更多相关文章
- checkedListBox
checkedListBox一键删除多个选中items private void button3_Click(object sender, EventArgs e) { ; i < checke ...
- Winform开发常用控件之Checkbox和CheckedListBox
Winform的开发基本都是基于控件事件的,也就是事件驱动型的. 多选框的放置和值的获取有很多种,这里介绍几个简单常用的方法 1.直接放置Checkbox,并获取Checkbox的值 上图 做法也非常 ...
- winform中的checkedListbox数据源绑定
首先看清楚一点 winform下该控件的名称叫做:checkedListbox webform下叫做CheckBoxList 不知道这样起名的用意何在,这个别管了,看看用法吧. web下很简单,直接设 ...
- C# Windows - ListBox&CheckedListBox
ListBox和CheckedListBox类的属性 属性 说明 SelectedIndex 这个值表明列表框中选中项的基于0的索引 ColumnWidth 在包含多个列的列表框中,这个属性指定列宽 ...
- CheckedListBox与CheckedListBox联动
包括保存和加载 //查找业务类型 DataTable dtyewu = sb.SelectSyscode(0, true); if (dtyewu.Rows.Count > 0) { flagc ...
- CheckedListBox与下拉框联动代码
private void yewubind(string id) { //给业务类型下拉框绑定业务类型数据 DataTable dtyewu = sb.SelectLast(id, 0); bool ...
- dev checkedlistbox动态绑定数据
最近在做项目的时候遇到个问题.用checkedlistbox控件绑定数据.在这里稍微总结一下. 其实动态绑定数据有两种方法下面说一下 1.通过数据源 DataTable dt=new DataTabl ...
- WinForm(C#)CheckedlistBox绑定数据,并获得选中的值(ValueMember)和显示文本(DisplayMember)
本文中我将和大家讨论关于在WinForm开发中给CheckedlistBox空间绑定数据源,并获取控件中选中的所有元素的显示文本(DisplayMember)和对应的实际值(ValueMember)的 ...
- C# CheckedListBox控件的使用方法
1. 加入项 checkedListBox1.Items.Add("蓝色"); checkedListBox1.Items.Add("红色"); checked ...
- winform checkedlistbox 设置行颜色
重写OnDrawItem事件 public class ColorCodedCheckedListBox : CheckedListBox{ protected override void OnDra ...
随机推荐
- kali linux 破解wpa密码
apt-get update apt-get install hostapd-wpe ls -l /etc/hostapd-wpe/ nano /etc/hostapd-wpe/hostapd-wpe ...
- SpringBoot定制错误页面
(1)有模板引擎的情况下,例如404错误,将会在thymeleaf的templates的error下寻找404.html,如果找不到再寻找4xx.html *所有4开头的错误状态码如果找不到特定的ht ...
- android camera(一):camera模组CMM介绍【转】
转自:https://blog.csdn.net/kevinx_xu/article/details/8821818 androidcmm图像处理工作手机三星 关键词:android camera ...
- 找到多个与名为“Home”的控制器匹配的类型的解决方案
主地址:http://localhost:3412/Home/Index 区域地址:http://localhost:3412/T200/Home/Index 解决方法: 注册路由添加命名空间(nam ...
- 【转】CString与string、char*的区别和转换
我们在C++的开发中经常会碰到string.char*以及CString,这三种都表示字符串类型,有很多相似又不同的地方,常常让人混淆.下面详细介绍这三者的区别.联系和转换: 各自的区别 char*: ...
- C++11中智能指针的原理、使用、实现
目录 理解智能指针的原理 智能指针的使用 智能指针的设计和实现 1.智能指针的作用 C++程序设计中使用堆内存是非常频繁的操作,堆内存的申请和释放都由程序员自己管理.程序员自己管理堆内存可以提高了程序 ...
- Android 图片平铺效果
我们大家都看过平铺的效果,那么我们都是怎么样才能实现的那,我们其实主要用到的就是api,我们一开始new一个bitmap,就可以了,但是,大家都没有想过,我们还可以用什么方法来做这个事情那,那么我们就 ...
- matplotlib画堆叠条形图
import matplotlib.pyplot as plt%matplotlib inlineplt.style.use('ggplot') plt.style.use("ggplot& ...
- javascript 练习题目答案1
以下是这个教程的答案 https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/00143 ...
- Fiddler抓包10-会话框添加查看get与post请求类型
前言 在使用fiddler抓包的时候,查看请求类型get和post每次只有点开该请求,在Inspectors才能查看get和post请求,不太方便.于是可以在会话框直接添加请求方式. 一.添加会话框菜 ...