Help with setting SelectedValue on the combobox

iboux

New member
Joined
Jun 7, 2005
Messages
2
Programming Experience
1-3
Hello
I was trying to find a solution to my problem with combobox
Here is my problem. I have 2 combobox and I have created a realtionship between them, so the value of the second combo will depent on the selection of the first. Now my problem is how do I set the SelectedValue to the Organization_ID like I did with setting the DisplayMember to Organization_Name? Here is the code(I'm using access DB):
" Dim ds As New DataSet
Dim cmdString As String = "select * from tblOrganization"
Dim da As New OleDb.OleDbDataAdapter(cmdString, con)
da.Fill(ds, "tblOrganization")

cmdString = " select * from tblAccount"
da = New OleDb.OleDbDataAdapter(cmdString, con)
da.Fill(ds, "tblAccount")

Dim relation As New DataRelation("ArtAuth", _
ds.Tables("tblOrganization").Columns("Organization _ID"), _
ds.Tables("tblAccount").Columns("OrganizationID") _
)
ds.Relations.Add(relation)

cbOrg.DataSource = ds
cbOrg.DisplayMember = "tblOrganization.Organization_Name"
cbOrg.SelectedValue = "tblOrganization.Organization_ID"


cbAccount.DataSource = ds
cbAccount.DisplayMember = "tblOrganization.ArtAuth.AccountName"
cbAccount.ValueMember = "tblOrganization.ArtAuth.AccountID""
 
Don't set the selected value.... use the ValueMember property instead.... then use a DataBinding to bind the selectedValue to the Org ID.

-tg
 
Back
Top