Samio

Samio

  • NA
  • 201
  • 176.7k

Populate Combobox2 according to Combobox1 content, LINQ to Entities in Windows Forms

Mar 26 2012 8:04 AM
Hi,

In order to populate ComboBox2 with the tasks of the selected Employee in ComboBox1, I need to retrieve the the EmployeeID from the ComboBox1. Could not get the following code to work:

private void Form1_Load(object sender, EventArgs e)
{
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities()) ;
ObjectQuery<Employee> Emp = MyEntities.Employee;
comboBox1.DataSource = from u in Emp select new { u.ID, u.LastName };
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "LastName";
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

ObjectQuery<Tasks> Tsk = MyEntities.Tasks;
comboBox2.DataSource = from u in Tsk where u.EmloyeeID = comboBox1.SelectedValue select new { u.EmloyeeID, u.TaskName };
comboBox2.ValueMember = "EmployeeID";
comboBox2.DisplayMember = "TaskName";
}

Answers (33)