Populating a cbo with values from table

Pace

Well-known member
Joined
Sep 2, 2005
Messages
90
Location
Manchester UK! :)
Programming Experience
1-3
Populating a cbo with values from table - SOLVED

Hi all,

I really apologise for my noobishness here...

This is a really cool forum btw :) can see me here for a bit :) but getting at my point. company uses an Access db app with a sql backend... now im kind of playing with .net particulary vb.net and windows forms...

Now I have gotten my head round these data adapters and data sets, but what I want to do is fill a combo box.

Say I have a table with 3 names in it, I can bind the data to the cbo but only the first record appears. Can somebody tell me how I would fill the cbo with all the names in the table... Is it something to do with an array?

To be honest I dont even need the full answer, I just need some kind hearted guidance as to where I could learn how to do this.

Thanks a million.

Barry
 
Last edited:
Hey Pace,

If you've bound the combobox then it should show all of the records in the table of the dataset to which you've bound, so this sounds kinda strange. To bind the combobox to a dataset you set its DataSource to the dataset or datatable and its displaymember to the field you wish to display, but it sounds like you already know that.

eg
VB.NET:
[/color]
[color=#0000ff][/color] 
[color=#0000ff]Me[/color].ComboBox1.DataSource = [color=#0000ff]Me[/color].DsAllTables1
[color=#0000ff]Me[/color].ComboBox1.DisplayMember = "clients.firstname"
 
Hi Badger!

Thanks for your reply...

I have bound my control to the relevant part of my dataset and here is the code, can you see anything wrong with it, or why it would only initially show a customer, but when I drop it I cant see anymore;

VB.NET:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.DsCust1.Clear() 

Me.OleDbDataAdapter1.Fill(DsCust1)

End Sub
 
Hey,

Looks good to me, the only thing i can think of is that the Select String of the dataadapter is only bringing back a single record. Try re-creating the dataadapter. The only other unlikely possiblity I can think of is that the combobox's MaxDropDownItems property is set to 1. Edit.. Can you also explain how you've got it bound?
 
Thank you so kindly for your help so far Badger... I have tried re-creating the data set and data adapter... I have included some screens...

Im not sure, do I have the right code for the items?

Do I not need a statement to say for each entity in this dataset, create an item? again I apologise if I seem bland... but I think im learning quickly :)

dsExample.gif

When I run the form however...
dsExample2.gif
 
Hey Pace,

Looks like the dataadapter's fine.. The only other thing i can think of is if you've bound to the text member instead of the displaymember. You shouldn't need to add an item for each record as the databinding should take care of that.
 
Last edited:
BadgerByte said:
Hey Pace,

Looks like the dataadapter's fine.. The only other thing i can think of is if you've bound to the text member instead of the displaymember. You shouldn't need to add an item for each record as the databinding should take care of that.

HEHE! My friend, you truly are a star! Thanks for your help, you were exactly right.

Thanks again!

Barry
 
Back
Top