zoukankan      html  css  js  c++  java
  • C# WinForm ComboBox 枚举 选定值

    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 Form2 : Form
    {
    public Form2()
    {
    InitializeComponent();
    this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
    }

    [Flags]
    [Serializable]
    enum Kind
    {
    现金支付
    = 0x0001,
    银行支付
    = 0x0002,
    }

    private void Form2_Load(object sender, EventArgs e)
    {
    var items
    = new System.Collections.ArrayList(Enum.GetValues(typeof(Kind))).ToArray();

    //Items 加载 默认选择为空
    //DataSource 加载 默认选择为首项
    this.comboBox1.Items.Clear();
    this.comboBox1.Items.AddRange(items);
    //this.comboBox1.DataSource = items;
    }


    private void button1_Click(object sender, EventArgs e)
    {
    if (this.comboBox1.SelectedItem != null)
    {
    var item
    = (Kind)this.comboBox1.SelectedItem;
    int value = item.GetHashCode(); //value = 1
    }

    //设置 combobox 的值
    //Items DataSource 都适用
    this.comboBox1.SelectedItem = Kind.银行支付;
    }
    }
    }

      

  • 相关阅读:
    jmeter跨平台执行时的文件路径问题
    jenkins配置
    jmeter--负载测试
    jmeter-脚本制作
    jmeter学习-性能指标、jmeter初识
    功能测试--其他
    功能测试--Fiddler
    功能测试--APP专项
    功能测试--基础(二)
    功能测试-基础(一)
  • 原文地址:https://www.cnblogs.com/LinFx/p/2123667.html
Copyright © 2011-2022 走看看