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

Reading number is top 10 articles
通过System.Web.Mail程序发邮件_[Asp.Net教程]
c#中的错误处理
入门学习之透析PHP的配置文件php.ini_php资料_编程技术
delphi获取指定磁盘中剩余空间
C#教程:MailMessage类和SmtpClient类使用实例
ASP.NET2.0中配置文件的加密与解密_[Asp.Net教程]
C++类与对象概念解析
Asp.net,2.0,Treeview,无限级无刷新示例_[Asp.Net教程]
从数据库导出数据到word、excel、.txt_.net资料_编程技术
Asp.NET大文件上传组件开发总结(二)---提取文件内容_[Asp.Net教程]
Reading number is top 10 pictures
福利福利。。。。。。
牛奶和人奶哪个好?
色狗系列
Li Zongrui hunting video screenshots1
The money of more than 100 countries and regions10
西方气质的东方美女2
This is heaven to some path
Sexy women in 2013--1
2012 national geographic daily picture3
A man's favorite things16
Download software ranking
The Bermuda triangle3
Unix video tutorial17
Boxer's Top ten classic battle7
实战黑客不求人
Red cliff
虚拟机汉化软件
JSP+Ajax Web development typical examples
功夫熊猫2(上集)
Tram sex maniac 2 (H) rar bag16
Boxer's Top ten classic battle2
qq published in(发表于) 2014/7/11 9:16:02 Edit(编辑)
C#中ComboBox控件应用实例

C#中ComboBox控件应用实例

C#中ComboBox控件应用实例

ComboBox控件

1.功能

ComboBox控件用于在下拉组合框中显示数据,它结合了TextBox控件和ListBox控件的功能。使用此控件时,可以在组合框中输入文本项,也可以从列表中选择项。图1为ComboBox控件。



图1 ComboBox控件

2.属性

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



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

下面详细介绍DropDownStyle属性,该属性用来设置ComboBox控件的显示样式。

语法:

public ComboBoxStyle DropDownStyle { get; set; }
属性值:ComboBoxStyle值之一,默认为 DropDown。

ComboBoxStyle:用来指定ComboBox样式。

DropDownStyle:设置的样式值。值为DropDown时,表示文本部分可编辑,用户必须单击箭头按钮来显示列表部分,这是默认样式;值为DropDownList时,用户不能直接编辑文本部分,用户必须单击箭头按钮来显示列表部分;值为Simple时,文本部分可编辑,而且列表部分可见。

示例

ComboBox控件样式

本示例将ComboBox控件的DropDownStyle属性设置为“DropDownList”,示例运行结果如图2所示。



图2 DropDownStyle属性

程序主要代码如下:

this. cmbDownStyle.DropDownStyle =ComboBoxStyle.DropDownList;
3.方法

(1)Select方法。该方法从ComboBox中选取指定的项。

(2)SelectALL方法。该方法用来选择ComboBox控件的可编辑部分的所有文本。

语法:

public void SelectAll ()
完整程序代码如下:

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

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_06

{

static class Program

{

///



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

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmCombox());

}

}

}

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

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Data.SqlClient;

using System.Windows.Forms;

namespace _8_06

{

public partial class frmCombox : Form

{

public frmCombox()

{

InitializeComponent();

}

private void frmCombox_Load(object sender, EventArgs e)

{

this.cmbDownStyle.DropDownStyle = ComboBoxStyle.DropDownList;

SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=zhy");

con.Open();

SqlCommand com = new SqlCommand("select * from student", con);

SqlDataReader dr = com.ExecuteReader();

this.cmbDownStyle.Items.Clear();

while (dr.Read())

{

this.cmbDownStyle.Items.Add(dr[0].ToString());

}

dr.Close();

con.Close();

}

private void cmbDownStyle_SelectedIndexChanged(object sender, EventArgs e)

{

//this.comText.Text = this.cmbDownStyle.SelectedItem.ToString();

}

private void BntSelectALL_Click(object sender, EventArgs e)

{

//this.comText.SelectAll();

}

}

}

★★★★★frmCombox窗体代码文件完整程序代码★★★★★


添加到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.