C# WinForm ComboBox 自定义数据项 (ComboBoxItem )
2011-07-22 09:29
239 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } public struct ComboBoxItem<TKey, TValue> { private TKey key; private TValue value; public ComboBoxItem(TKey key, TValue value) { this.key = key; this.value = value; } public TKey Key { get { return key; } } public TValue Value { get { return value; } } public override string ToString() { return Value.ToString(); } } private void Form3_Load(object sender, EventArgs e) { //KeyValuePair<int, string> keys = new KeyValuePair<int,string>(); this.comboBox1.Items.Add(new ComboBoxItem<int, string>(1, "Lin")); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { var item = (ComboBoxItem<int, string>)this.comboBox1.SelectedItem; Text = item.Value; } } }
一个 1月 到12 月的下拉单
for (int i = 1; i <= 12; i++) { this.comboBox1.Items.Add( new ComboBoxItem<int, string>(i, String.Concat(i.ToString().PadLeft(2, '0'), "月"))); }
相关文章推荐
- c#(winform)中自定义ListItem类方便ComboBox和ListBox添加项完全解决
- C#之WinForm基础 清空comboBox下的所有可选数据项
- C#之WinForm基础 comboBox1.SelectedIndex得到控件中被选中数据项的索引值
- c#(winform)中自定义ListItem类方便ComboBox和ListBox添加项完全解决(DropDownList 和Combox 数据绑定的常用方法) .
- c#(winform)中自定义ListItem类方便ComboBox和ListBox添加项完全解决(DropDownList 和Combox 数据绑定的常用方法)
- c#(winform)中自定义ListItem类方便ComboBox添加Item项
- C#(Winform)中ComboBox中添加项(ListBox)类的自定义过程
- c#(winform)中自定义ListItem类方便ComboBox和ListBox添加项完全解决
- C# winform combobox 在绑定数据之后插入一项选择项
- C# winform 自定义鼠标图标
- C#实现Winform自定义半透明遮罩层
- C#_WinForm的ComboBox与数据绑定详解(关于Text属性和下拉列表)
- C# Winform中的ComboBox控件绑定数据库项目作为列表内容
- 自定义ComboBox控件,完美解决C#自带的ComboBox效率慢的问题
- C# WPF下自定义ComboBox背景、边线、颜色等代码实现
- winform 自定义combobox(组合框)
- 【转】c# winform 打包部署 自定义界面 或设置开机启动
- [转]C# winForm 自定义鼠标样式的两种方法
- c#(winform)中ComboBox和ListBox添加项完全解决
- C#之WinForm基础 新建一个不可编辑的comboBox