Solved

Combobox population with Linq in VB2008

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Populate DataModel with DataTable 44 28
How to join on ID, with prefix? 15 58
application restarter  - for an exe that hangs 9 25
SQL Help 27 40
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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