第一步:先创建一个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. 洛谷P1601 A+B Problem(高精)

    题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 输出格式: 输 ...

  2. 【2】数据采集 - urllib模块

    python2环境下关于urllib2的使用可以学习这篇文章.本文主要针对python3环境下使用urllib模块实现简单程序爬虫. 链接:https://www.jianshu.com/p/3183 ...

  3. 元素类型为 "session-factory" 的内容必须匹配 "(property*,mapping*,(class-cach....解决方法

    http://www.cnblogs.com/kisso143/p/3642057.html property必须写在mapping的上面.

  4. redis开发为什么选用skiplist?

    There are a few reasons: 1) They are not very memory intensive. It's up to you basically. Changing p ...

  5. ssh的tunnel设置+autossh设置

    tunnel设置 一.说明 用于通过ssh转发数据 二.设置 编辑ssh server的'2Fetc/ssh/sshd_config 加入下面: #反向遂道 GatewayPorts  yes #正向 ...

  6. TRIZ系列-创新原理-8-重量补偿原理

    重量补偿原理的表述例如以下: 1)将某一物体与还有一种提供上升力的物体组合,以补偿其重量:2)通过与环境(利用空气动力,流体动力或其他力等)的相互作用.实现对物体的重量补偿: 重力使得我们能够稳稳的依 ...

  7. scala并发编程原生线程Actor、Case Class下的消息传递和偏函数实战

    參考代码: import scala.actors._ case class Person(name:String,age:Int) class HelloActor extends Actor{ d ...

  8. ViewPage+Frament+listView滑动效果

    近期在做一个须要使用Frament+ViewPage制作一个滑动的效果,看了非常多资料,最终实现了,这与大家分享一下战果 总结一下.这里我做了一个Demo分享给大家 我的文件文件夹结构图 1.首先要有 ...

  9. 【cl】找不到火狐Cannot find firefox binary in PATH

    org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is ins ...

  10. NS3网络仿真(3): NetAnim

    快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 在NS3提供的演示样例first.py中,并没有生成NetAnim所须要的xml文件,本节我们尝试 ...