All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
精通数据库系列之入门-技巧篇3_mssql学习_编程技术
ASP.NET技巧:DataGrid的多行提交_[Asp.Net教程]
ASP.NET,1.1,无,Cookie,SessionID,重写_.net资料_编程技术
php函数substr实现asp中left和right功能_php资料_编程技术
AJAX实例:根据邮编自动完成地址信息_[AJAX教程]
JS的IE和Firefox兼容性汇编_JavaScript技术_编程技术
如何解决Remoting无法传输存储过程参数的问题_[Asp.Net教程]
asp.net,取得远程的IP地址和浏览器类型_[Asp.Net教程]
新瓶旧酒ASP.NET,AJAX系列文章索引_[Asp.Net教程]
如何在十天内学会php之第一天_[PHP教程]
Reading number is top 10 pictures
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line2
Desktop Wallpapers1
The terra-cotta warriors1
The most popular girls welcome eggplant
Men's and women's orgasms
XuYing poker perspective garment debut
Beautiful Japanese beauty(漂亮的日本美女)2
BingBingFan apple dew point photo gallery1
住院一星期,检测费两万
Poor doll, hand job was caught the currently in effect by his dad
Download software ranking
终极变速大师Speeder3.26
Unix video tutorial8
Boxer vs Yellow1
Take off clothes to survival
Boxer's Top ten classic battle8
Sora aoi, the maid, students' uniforms
Proficient in Eclipse
asp.netWeb服务器高级编程
Prostitutes diary
变速齿轮3.26
qq published in(发表于) 2014/7/11 9:16:00 Edit(编辑)
C#中CheckedListBox控件应用实例

C#中CheckedListBox控件应用实例

C#中CheckedListBox控件应用实例

CheckedListBox控件

1. 功能

CheckedListBox控件扩展了ListBox控件,它几乎能完成列表框可以完成的所有任务,并且还可以在列表中的项旁边显示复选标记。CheckedListBox控件与ListBox控件的主要差异在于复选列表框只能有一项选中或未选中任何项。注意,选定的项在窗体上突出显示,与已选中的项不同。图1为CheckedListBox控件。



图1 CheckedListBox控件

2.属性

CheckedListBox 控件常用属性及说明如表1所示。



表1 CheckedListBox控件常用属性及说明

下面对比较重要的属性进行详细介绍。

(1)Items属性。此属性用于向控件中添加项。

语法:

public ObjectCollection Items { get; }

属性值:代表CheckedListBox中项的CheckedListBox.ObjectCollection集合。

(2)CheckedItems属性。此属性是指CheckedListBox控件中所有选中项的集合。

语法:

public CheckedItemCollection CheckedItems { get; }

属性值:CheckedListBox的CheckedListBox.CheckedItemCollection集合。

示例

Items属性的使用

本示例实现效果为:当程序运行时,单击【确定】按钮,利用Items属性将选择的项添加到Checked ListBox 控件中。

程序主要代码如下:

if (this.checkBox1.Checked == True)

{

this.checkedListBox1.Items.Add(checkBox1.Text);

}

if (this.checkBox2.Checked == True)

{

this.checkedListBox1.Items.Add(checkBox2.Text);

}

if (this.checkBox3.Checked == True)

{

this.checkedListBox1.Items.Add(checkBox3.Text);

}

3.方法

CheckedListBox控件常用方法及说明如表2所示。



表2 CheckedListBox控件常用方法及说明

下面详细介绍SetItemCheckState方法,此方法用于设置当前的复选状态。

语法:

public void SetItemCheckState (int index,CheckState value)

index:要为其设置状态的项的索引。

value:CheckState值之一。

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_10

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmCheckBox());

}

}

}

★★★★★frmCheckBox窗体设计文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _8_10

{

public partial class frmCheckBox : Form

{

public frmCheckBox()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (this.checkBox1.Checked == false && this.checkBox2.Checked ==false && checkBox3.Checked == false)

{

MessageBox.Show("至少选一项爱好");

return;

}

if (radioButton1.Checked == false && radioButton2.Checked == false)

{

MessageBox.Show("请选择性别");

return;

}

this.checkedListBox1.Items.Clear();//清除当前数据

if (this.checkBox1.Checked == true)

{

this.checkedListBox1.Items.Add(checkBox1.Text);

}

if (this.checkBox2.Checked == true)

{

this.checkedListBox1.Items.Add(checkBox2.Text);

}

if (this.checkBox3.Checked == true)

{

this.checkedListBox1.Items.Add(checkBox3.Text);

}

if (this.radioButton1.Checked == true)

{

this.checkedListBox1.Items.Add(radioButton1.Text);

}

if (this.radioButton2.Checked == true)

{

this.checkedListBox1.Items.Add(radioButton2.Text);

}

this.checkBox1.Checked = false;

this.checkBox2.Checked = false;

this.checkBox3.Checked = false;


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.