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)
{
LoadUsersToComboBox();
}
This method will load a comboBox with value only on the FIRST time, but not on subsequent attempts:
private void LoadUsersToComboBox()
{
comboBox1.DataSource = peopleRepo.FindAllPeople(); /*Return IQueryable<Person>*/
}
And this loads every time I call LoadUsersToComboBox():
private void LoadUsersToComboBox()
{
comboBox1.DataSource = peopleRepo.FindAllPeople().ToList();
}
Why does the first one only load the first time?
Here is the code to the PeopleRepository class:
namespace SQLite_Testing_Grounds
{
public class PersonRepository
{
private ScansEntities3 db = new ScansEntities3();
public IQueryable<Person> FindAllPeople()
{
return db.People;
}
}
}