第一步:先创建一个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. 【sqli-labs】 less40 GET -Blind based -String -Stacked(GET型基于盲注的堆叠查询字符型注入)

    提交,页面正常,说明是')闭合的 http://192.168.136.128/sqli-labs-master/Less-40/?id=1')%23 http://192.168.136.128/s ...

  2. (转)基于Metronic的Bootstrap开发框架经验总结(4)--Bootstrap图标的提取和利用

    http://www.cnblogs.com/wuhuacong/p/4762924.html 在前面的一篇随笔<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模 ...

  3. java HttpURLConnection 登录网站 完整代码

    import java.io.*; import java.util.*; import java.net.*; public class WebTest { public static void m ...

  4. 实体服务器安装centos7过程记录

    一次在实体服务器安装centos 7的过程记录 第一次在实体服务器上面安装服务器(centos 7),在此记录安装过程中遇到的一些坑. 系统版本:CentOS Linux release 7.6.18 ...

  5. springboot框架嵌入netty

    1.pom.xml添加依赖 <dependency> <groupId>io.netty</groupId> <artifactId>netty-all ...

  6. elementUI 图片上传限制上传图片的宽高

    文件上传,需当上传的文件类型为图片的时候,需要限制图片的宽高. 此处采用了new Promise异步加载的方式,等图片上传加载完成后, 页面代码: <el-form-item label=&qu ...

  7. 编写App测试用例的关注点

    如何做到测试用例的百分百覆盖一直是测试用例编写过程中的难点,首先在测试时我们经常会遇见一些常见的bug,那么我们可以在编写测试用例时考虑到这些点.    一:关于业务逻辑               ...

  8. (23)Spring Boot启动加载数据CommandLineRunner【从零开始学Spring Boot】

    [Spring Boot 系列博客] )前言[从零开始学Spring Boot] : http://412887952-qq-com.iteye.com/blog/2291496 )spring bo ...

  9. MySQL中index和key的关系

    KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY ...

  10. hdu 1713求分数的最小公倍数

    题意中的圈数和天数说反了 #include<stdio.h> __int64 gcd(__int64 a,__int64 b) {/* 比如4/3 3/5 通分20/15 9/15 所以这 ...