?
Solved

Combobox population with Linq in VB2008

Posted on 2009-04-05
5
Medium Priority
?
494 Views
Last Modified: 2013-12-25
Hi, I am trying to populate a combobox with the employee id # from a sql table.  It seems to run the first two lines but doesn't populate and it doesn't like the third line. My VB is a little rusty and I am pretty hung up.
Dim empID = (From employee In db.employee Select employee.emp_id).ToList
        cmbEmpId.DataSource = empID
        cmbEmpId.DisplayMember = empID.First.ToString

Open in new window

0
Comment
Question by:litsnsirn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 100 total points
ID: 24075566
Here is poc in C# .. might get you in right direction
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace bindingListto_ComboBox
{
    public partial class Comboform : Form
    {
        public Comboform()
        {
            InitializeComponent();
        }

        private void comboform_Load(object sender, EventArgs e)
        {
            var Countries = new List<Country>
                                {
                                    new Country
                                        {
                                            Name = "Germany",
                                            Cities = {new City {Name = "Berlin"}, new City {Name = "Hamburg"}}
                                        },
                                    new Country
                                        {
                                            Name = "England",
                                            Cities = {new City {Name = "London"}, new City {Name = "Birmingham"}}
                                        }
                                };
            combo.DataSource = Countries;
            combo.DisplayMember = "Name";
            combo.ValueMember = "Name";
        }
    }

    public class Country
    {
        public Country()
        {
            Cities = new List<City>();
        }

        public string Name { get; set; }
        public IList<City> Cities { get; set; }
    }

    public class City
    {
        public string Name { get; set; }
    }
}
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 24313105
Try this
cmbEmpId.DataSource = db.employee.tolist
cmbEmpId.DisplayMember = "EmpID"
cbmEmpId.ValueMember = "EmpID"

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question