Solved

Combobox population with Linq in VB2008

Posted on 2009-04-05
5
493 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 25 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 25 total points
ID: 24313105
Try this
cmbEmpId.DataSource = db.employee.tolist
cmbEmpId.DisplayMember = "EmpID"
cbmEmpId.ValueMember = "EmpID"

Open in new window

0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 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