using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayMemberValueMember
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            Module m1=new Module();
            m1.ID=1;
            m1.DISPLAY="v1";

            Module m2=new Module();
            m2.ID=2;
            m2.DISPLAY="v2";
            List<Module> lm = new List<Module>();
            lm.Add(m1);
            lm.Add(m2);

            comboBox1.DataSource = lm;
            comboBox1.DisplayMember = "ID";
            comboBox1.ValueMember = "DISPLAY";

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox1.Text = ((Module)comboBox1.SelectedItem).DISPLAY;
            textBox2.Text = ((Module)comboBox1.SelectedItem).ID.ToString();
        }
    }

    public class Module
    {
        public Module()
        {
        }

        int Id;
        string display;

        public int ID
        {
            set { Id = value; }
            get { return Id; }
        }

        public string DISPLAY
        {
            set { display = value; }
            get { return display; }
        }
    }
}

相关文章:

  • 2022-02-16
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2021-08-13
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2021-09-30
  • 2021-11-10
  • 2022-12-23
  • 2021-10-26
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案