Datasets and comboboxes

banks

Well-known member
Joined
Sep 7, 2005
Messages
50
Programming Experience
Beginner
Hello all,

I know this topic has been covered numerous times, but every Q doesn't start from the begining.

I simply have a form with a combobox on (cboSupplier) I want to fill it with supplier name from my Access table (tblSupplier) taking the supplierID and supplierName....

Now i get confused with knowing what to use in terms of a dataset. What on earth is the easiest function to use? I am looking at oleDB stuff and getting confused. How do i firstly create a dataset, then apply it to my combo???

Many thanks guys and gals'

Alex
 
crap, the version of vis studio is newer than mine, but i can look at the source code still, so i'll give it a try
 
For those who need help about the same problem this is short explanation:
Means, 1st you suppose to make a class which you will call each time you want to populate any comboBox:
VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] PopulatingClass
[/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] PopulateCombos([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strTable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] cmbControl [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ComboBox)
ds = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet
da = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbDataAdapter("SELECT * FROM " + strTable, oledbcon)
da.Fill(ds, strTable)
cmbControl.DataSource = ds.Tables(0)
cmbControl.ValueMember = ds.Tables(0).Columns(0).ToString
cmbControl.DisplayMember = ds.Tables(0).Columns(1).ToString
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

then just instantiate the class and enter the parameters respectively:
VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] populating [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PopulatingClass = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PopulatingClass
populating.PopulateCombos("tblSupplier", [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ComboBox1)[/SIZE]

I hope it is enough clear explained ... lol

Regards ;)
 
God damn it - it does work - i had the wrong path to a different database with the same tablename, so i was getting random output. Works now cheers...

While i'm here, if i want to 'hard code' in two values for a combobox - ie, the combo will pull down and display 'open' and 'closed' - these will only ever be the two options so no need for a table. How do i do this??
 
There's a property for comboboxes called 'Collection' click the "..." and add each item to a new line
 
Cool, got em all working great now...
1 thing tho, it displays the first value in the table automatically - can i change it so that a value isn't in the combo when it loads up - ie it is just blank, then you hit the combo and see the options.
 
if you set the text property to nothing it should do that by default, or for some reason if it doesnt do
VB.NET:
Expand Collapse Copy
combobox.selectedindex = -1
 
Back
Top