public Form1() { InitializeComponent(); comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "ID"; LoadUsersToComboBox(); } PersonRepository peopleRepo = new PersonRepository(); private void LoadUsersToComboBox() { comboBox1.DataSource = peopleRepo.FindAllPeople().ToList(); } private void button2_Click(object sender, EventArgs e) { CreateNewPerson(); LoadUsersToComboBox(); } private void CreateNewPerson() { if (textBox2.Text != String.Empty) { Person user = new Person() { Name = textBox2.Text }; peopleRepo.Add(user); peopleRepo.Save(); } } This method will load a comboBox with value only on the FIRST time, but not on subsequent attempts:
Why does the first one only load the first time?
Thanks
Edit:
Here is the code to the PeopleRepository class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SQLite_Testing_Grounds { public class PersonRepository { private ScansEntities3 db = new ScansEntities3(); public IQueryable<Person> FindAllPeople() { return db.People; } public Person FindPerson(int id) { return db.People.SingleOrDefault(p => p.ID == id); } public void Add(Person person) { db.AddToPeople(person); } public void Delete(Person person) { foreach (var department in person.Departments) { db.DeleteObject(department); } db.DeleteObject(person); } public void Save() { db.SaveChanges(); } } }