FANDOM


  1. Create a Form1 with listBox1 and button1
  2. Set DisplayMember property of listBox1 to LongName
  3. Set ValueMember property of listBox1 to ShortName
    struct State
    {
        public string ShortName { get; set; }
        public string LongName { get; set; }
    }

    System.ComponentModel.BindingList<State> States;

    private void Form1_Load(object sender, EventArgs e)
    {
        States = new System.ComponentModel.BindingList<State>();

        States.Add(new State { ShortName = "AL", LongName = "Alabama" });
        States.Add(new State { ShortName = "AK", LongName = "Alaska" });
        States.Add(new State { ShortName = "AZ", LongName = "Arizona" });
        
        listBox1.DataSource = States;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        States.Add(new State { ShortName = "CA", LongName = "California" });
    }

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.