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
Initialize Combo box with a blank item - LINQ C#
Mar 30 2012 10:35 AM
I would like to initialize my combo box with a set of items, the first item should be blank, and this is my code:
private void Form1_Load(object sender, EventArgs e)
{
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
ObjectQuery<Employee> Emp = MyEntities.Employee;
//comboBox1.Items.Insert(0, String.Empty);
comboBox1.DataSource = (from u in Emp select new { u.ID, u.LastName }).ToList();
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "LastName";
label1.Text = comboBox1.SelectedValue.ToString();
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex.ToString() == "0") return;
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
ObjectQuery<TasksPerEmployee> Tsk = MyEntities.TasksPerEmployee;
label1.Text = comboBox1.SelectedValue.ToString();
int val = Convert.ToInt32(comboBox1.SelectedValue.ToString());
comboBox2.DataSource = (from t in Tsk where t.EmployeeID == val select new { t.ID, t.TaskName }).ToList();
comboBox2.ValueMember = "ID";
comboBox2.DisplayMember = "TaskName";
}
}
Reply
Answers (
1
)
Basics clarification
LINQ to Entities - how to get column value in a combobox selection