0
私は1つのWinFormに2つのコンボボックスがあり、最初はEmployee名で満たされ、2番目のものはリストされたすべての従業員に影響を受けるタスク最初のコンボ。ComboBox1の変更はComboBox1の変更になります - LINQ EF Winform C#
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 }).ToList();
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "LastName";
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex.ToString() == "0") return;
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
label1.Text = comboBox1.SelectedValue.ToString();
ObjectQuery<Tasks> Tsk = MyEntities.Tasks;
comboBox2.DataSource = (from t in Tsk where t.EmloyeeID.ToString() == comboBox1.SelectedValue.ToString() select new { t.ID, t.TaskName }).ToList();
comboBox2.ValueMember = "ID";
comboBox2.DisplayMember = "TaskName";
}
}
が正常にComboBox1のではなく、ComboBox2を記入でき、ComboBox1の最初の行が空白の場合、それは素晴らしいことだ。しかし、次のコードは、2番目のコンボのために実行することができませんでした。