zoukankan      html  css  js  c++  java
  • C# WinForm ComboBox 自定义数据项 (ComboBoxItem )

    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'), "月")));
                }
    

      

  • 相关阅读:
    数学与基本思维
    思考与知识
    数学思想
    肥胖是罪、食物有毒
    高血压成因
    心脑血管疾病
    知行合一与人
    所谓的成长就是认知升级-成长就是应付自如
    深度思考
    “三高”即通常所说的高血压、高血脂(血脂异常)和高血糖三种病症的总称
  • 原文地址:https://www.cnblogs.com/LinFx/p/2123666.html
Copyright © 2011-2022 走看看