Solved

Combobox population with Linq in VB2008

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
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…

808 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