Solved

Combobox population with Linq in VB2008

Posted on 2009-04-05
5
488 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now