none
Populating Combo Boxes using LINQ to SQL RRS feed

  • Question

  • Hello,

     

    I've done a few hours of searching on how to do this to no avail. I'm trying to dynamically populate a combobox using data from a field in a database. I'm able to retreive one record....and that's the first in the table. I'm thinking I'm close (maybe, I hope) but I'm missing something that is probably quite unsubtle...

     

    Here's my code snippet...

    Code Snippet

     

    Public Class Form1

     

    Dim db As DataClasses1DataContext

     

    'in the load routine to populate the box

    Me.Vehicle_operatorBindingSource.DataSource = db.vehicle_operators

     

     

    I've followed the directions from Beth Massi's tutorials and I'm only getting the first value...Does anyone else know another way to dynamically populate a combobox so it'll pull a name from a field in a table? (SQL)
    Friday, August 22, 2008 5:45 PM

Answers

  • You should set the DisplayMember property of the combo box to be the name of the property of a vehicle_operator you wish to display.

     

    You can also set the ValueMember property to determine what property the .Value result will return.

     

    This is normal data-binding behaviour for many controls (not specific to LINQ to SQL or combo boxes).

     

    [)amien

    Friday, August 22, 2008 7:01 PM
    Moderator

All replies

  • You should set the DisplayMember property of the combo box to be the name of the property of a vehicle_operator you wish to display.

     

    You can also set the ValueMember property to determine what property the .Value result will return.

     

    This is normal data-binding behaviour for many controls (not specific to LINQ to SQL or combo boxes).

     

    [)amien

    Friday, August 22, 2008 7:01 PM
    Moderator
  • Thanks. After a bti of nosing around I found it too. I'm picking up VB again after a few years hiatus.
    Wednesday, August 27, 2008 1:01 PM