第一步:先创建一个WinForm窗体应用程序,按照下图所示的进行布局。

第二步:为ComboxBox控件、checklistbox控件和listbox控件和button控件设置属性

第三步:在代码中的窗体类中声明两个私有数组。

private string[] names;
private string[] nums;

第四步:在窗体类中初始化数组和做一个准备工作。

private void Form1_Load_1(object sender, EventArgs e)
{
names = new string[] { "jason", "jack", "jay", "baby" };
nums = new string[] { "12345", "21345", "32145", "42135" };
this.checkedListBox1.Items.Add(names);
this.comboBox1.SelectedIndex = 0;
}

第五步:为button按钮添加触发事件。

 private void button1_Click(object sender, EventArgs e)
{
//count是用来获得checkedListBox中被选中的个数
int Count = this.checkedListBox1.CheckedItems.Count;
if (this.checkedListBox1.Items.Count == 0) return;
//如果checkedListBox一个都没有被选中
if (this.checkedListBox1.SelectedIndex == -1)
{
MessageBox.Show("请在CheckListBox中选择要添加的项");
return;
}
//将选中的项加入到listbox中
for (int i = 0; i < Count; i++)
{
this.listBox1.Items.Add(this.checkedListBox1.CheckedItems[i]);
}
MessageBox.Show("选择的项已经移至ListBox中");
}

第六步:为comboBox控件添加触发事件,当控件中的值是姓名时则将数组中的放入到checkedlistbox中。

     /// <summary>
/// 此方法是当在comboBox中选择了某个字段就会在checkListBox中显示这个字段对应的选择项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cb = (ComboBox)sender;
switch (cb.SelectedIndex)
{
case 0:
this.checkedListBox1.Items.Clear();
this.checkedListBox1.Items.AddRange(names);
break;
case 1:
this.checkedListBox1.Items.Clear();
this.checkedListBox1.Items.AddRange(nums);
break;
}
this.listBox1.Items.Clear();
}

第七步:运行过程截图。

①开始界面:

②当选择checkedlistbox中的值并点击提交信息后截图:

③选择编号并选择checkedlistbox中的值并点击提交信息后截图:

第八步:大功告成。

ComboxBox控件、checklistbox控件和listbox控件的组合开发的更多相关文章

  1. c#控件攻略宝典之ListBox控件

    ListBox控件的使用: 1)控件属性 Items SelectedItems SelectioModes 2)数据绑定 DataSoure DisplayMember ValueMenber 3) ...

  2. 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...

  3. asp.net中的ListBox控件添加双击事件

    问题:在Aspx页里的ListBox A中添加双击事件,将选中项添加到另一个ListBox B中,双击ListBox B中的选中项,删除当前选中项 页面: <asp:ListBox ID=&qu ...

  4. 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

    1.ListBox 的示例Controls/SelectionControl/ListBoxDemo.xaml <Page x:Class="Windows10.Controls.Se ...

  5. WPF中ListBox控件在选择模式(SelectionMode)为Single时仍然出现多个Item被选中的问题

    最近在学习WPF过程中使用到了ListBox控件,在使用时遇到下面的奇怪问题: 代码如下: listBox.Items.Add("绘图"); listBox.Items.Add(& ...

  6. MATLAB GUI程序设计中ListBox控件在运行期间消失的原因及解决方法

    在运行期间,ListBox控件突然消失,同时给出如下错误提示: Warning: single-selection listbox control requires that Value be an ...

  7. MFC中Listbox控件的简单使用

    MFC中listbox控件是为了显示一系列的文本,每个文本占一行.   Listbox控件可以设置属性为: LBS_CHILD   :(默认)子窗口 LBS_Visible :(默认)可视 LBS_M ...

  8. 浅谈ListBox控件,将对象封装在listBox中,在ListBox中显示对象中某个属性,在ListBox中移除和移动信息

    大家好,俗称万事开头难,不经历风雨,怎能见彩虹.在此小编给大家带来一个自己练习的小实例,希望与大家一起分享与交流.下面进入应用场景,从SQL2008数据库取出数据,给ListBox赋值在界面并显示出来 ...

  9. 异步方式向WPF ListBox控件中一条一条添加记录

    向ListBox绑定数据源时,如果数据量过大,可能会使得程序卡死,这是就需要一条一条的向ListBox的数据源中添加记录了,下面是个小Demo: 1.前台代码,就是一个ListBox控件 <Wi ...

随机推荐

  1. python 生成测试报告并发送邮件

    前言: 使用unittest编写自动化测试脚本,执行脚本后可以很方便看到测试用例的执行情况. 但如果想向领导汇报工作,就需要提供更直观的测试报告. 思路: 使用unittest编写测试用例,HTMLT ...

  2. PAT_A1145#Hashing - Average Search Time

    Source: PAT A1145 Hashing - Average Search Time (25 分) Description: The task of this problem is simp ...

  3. 如何查看系统的界面,比如费用申请单的序时簿界面引用的是哪一个ListUi.快捷键alt+shift+d 然后选中该ListUI大框框,就可以看到引用的是哪一个了.

    如何查看系统的界面,比如费用申请单的序时簿界面引用的是哪一个ListUi.快捷键alt+shift+d 然后选中该ListUI大框框,就可以看到引用的是哪一个了.

  4. C# 常用语句

    var list = dt.AsEnumerable().Select(t => t.Field<string>("Bed")).ToList();Select( ...

  5. 一次由于 MTU 设置不当导致的网络访问超时

    转自:http://weibo.com/ttarticle/p/show?id=2309404140904511340923 API 服务正常,但是调用总是超时.api端日志显示,响应速度很快. ​​ ...

  6. 在oracle中将某个字段的数据作为列名的查询

    原表结构 查询语句: select sno,sname,sum(语文) 语文,sum(数学) 数学,sum(英语) 英语 from (select sno,sname,decode(subjiect, ...

  7. 从零开始创建一个 PHP 扩展

    创建一个扩展的基本步骤都有哪些.示例中,我们将实现如下功能: <?phpecho say();?> 输出内容: $ php ./test.php$ hello word 在扩展中实现一个s ...

  8. Happy 2006

    Happy 2006 Time Limit: 3000MS   Memory Limit: 65536K       Description Two positive integers are sai ...

  9. js简单自定义事件与主动触发事件

    var events = { addHandler: function (element, eventType, handler) { if (element.addEventListener) { ...

  10. 0816关于MySQL的审计 init-connect+binlog实现用户操作追踪

    转自:http://blog.sina.com.cn/s/blog_605f5b4f01013xkv.html mysql 用init-connect+binlog实现用户操作追踪 做access 的 ...