TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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";
}
Reply
Answers (
33
)
Reasons to prefer C#?
Sql connection Error