Results 1 to 3 of 3

Thread: Databound Combobox with Lookup Data in the List [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    57

    Databound Combobox with Lookup Data in the List [RESOLVED]

    I have tried to work this problem out but i'm just getting frustrated with it now!

    I have a simple form with databound fields on it. This is connected to an Access DB using DataAdapter and DataSets. Everything is sweet until i added a combobox to make life easier.

    You see, i have a field on my form (CountyID) containing an number relating to a County Name held in the COunty Table. I can get the combobox to show the number everytime i navigate to another record but i can't seem to work out how to show a list of county names.

    I might not have explained it too well but i'm sure you'll get the drift of what i'm looking to do.

    I'm sure someone has worked this problem out before. In VB6 it was easy as, but in .NET i can't seem to grasp it. Probably because i'm a little stupid (no comments please!)

    So if anyone can give me a helping hand i would appreciate it.
    Last edited by BorisMartian; Aug 20th, 2003 at 05:25 PM.

  2. #2
    New Member
    Join Date
    May 2003
    Posts
    8
    Boris:

    I was in the same boat as you, well, sort of. I wanted to display first and last name in the same combo box.

    I haven't check this post out closely yet since I just signed in now, but if it's of any interest to you, here is the link...

    http://www.vbforums.com/showthread.p...hreadid=258087

    EDIT:

    Boris:
    I've tested adding the extra field to the select statement, as recomended as by Lunatic3 (If your reading this, thanks so much for the help again)

    Try using something like this in your select statement...

    SELECT CountryID, CountryName, (isnull(CountryID,'') + ' ' + isnull(CountryName,'')) as NewFieldNameHere FROM TableNameHere

    This will add a temporary column to your dataset in the specified table. From this point you can bind your combo box to the new field your just created.

    This will have you combo box displaying the Country ID and the Country Name side by side.

    This may not be exactly what you are looking for ( I didn't fully understand your issue) but It helped me with a simular situation.
    Last edited by theonewhowas; Aug 20th, 2003 at 02:11 AM.
    ~~ The One Who Was ~~

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    57
    Thanks for that.

    It's not exactly what i was after but it will come in handy a little further on.

    Just to clarify. What i wanted the user to see in the combo was the Country Name and not the Country ID although in the actual field on the Table it saves the CountryID.

    Anyway i think i've worked out the way to do it!?!

    What you have to do is to make a DataAdapter for the lookup table. You then Create a DataSet for your Primary Table and include the Lookup Table in that.

    You then bind all controls to your primary table except for the combo box where you have to do things slightly different. In the:-
    DataSource you put the DataSet (without any table info).
    DisplayMember you put the CountryName (from the lookup table)
    ValueMember you put the CountryID (from the lookup table)
    SelectedValue you put the Dataset.CountryID (from the Primary table).

    This should get it working although it seems really long winded compared to the way you do it in VB6.

    I eventually found this from microsoft which explains better what to do.
    http://msdn.microsoft.com/vbasic/def...indowsform.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width