Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo from two datasets

Status
Not open for further replies.

thedman00

Programmer
Jun 11, 2003
46
AT
I am populating a combo box with data from a table in the database. That works fine. I then want to set the current value of the box using a value from a different dataset. I'm having some trouble with this. The dataset that I'm using to set the current value is only going to have one row in it.
 
I have an idea, but it might be easier if I saw the code that you have so far.

Ron

Ron Repp
 
isn't that the whole point of combo's one table to fill the list and one to flll the value?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Here is how I'm populating the combo:

Dim sqlStr2 As String = "SELECT Name FROM Man ORDER BY Name"
Dim da2 As OleDbDataAdapter = New OleDbDataAdapter(sqlStr2, OleDbConnection2)
da2.Fill(ds, "Man")
Dim dv2 As DataView = ds.Tables("Man").DefaultView
comboMan.DataSource = dv2
comboMan.DisplayMember = "Name"

I'm also creating another dataset by passing the row number from a previous window/form. I want to take a value from that dataset and set the current value of the combobox to that.
 
I see you set the displaymember, but what about the valuemember?

you can either databind to the selectedvalue property or set it everytime it changes via code

databinding would look something like this

comboman.databindings.add("selectedvalue",otherdatasetnaem,"fieldname")

or

comboman.selectedvalue = valuetoset

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
To be honest I'm real new to .net and am not sure what the displaymember and valuememeber represent. I tried doing the comboman.databindings.add("selectedvalue",otherdatasetnaem,"fieldname") but got the following error:

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: Cannot bind to property or column Man on DataSource.

How would I go about setting the selectedvalue property to the specific column of a specific row in the dataset?
 
As an fyi this is how i ended up doing it.
I populated one dataview and bound the combo to it then i used:

comboMan.FindString(DataSet11.Tables("tablename").Rows(CurrRow).Item("colname")).ToString()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top