Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello code masters,

Today I have been banging my head in the wall trying to figure this one out.

I have a combo box filled with values from table A field A
no issue on that, I am able to populate by filling my dataset with sql query and etc.

Now the problem is, this combo box should also change selected value based on another combo box coming from a different table, table B WHILE RETAINING THE VALUES FROM TABLE A just in case they wanted to change the selected value from table A to values from table B.


I have this code which selects data OnIndexChange of combo box from tableA where value = cmb1.value


On indexchange cmb1 =
VB
Dim ds As DataSet = SQL.RecOnChange(ojConn, BG) - select Field1 from tableA where field1 = cmb1.value

ojConn.Close()
If ds.Tables(0).Rows.Count > 0 Then
    Dim DT As New DataTable()
    DT = ds.Tables(0)
    cmb2.DataSource = DT
    cmb2.DisplayMember = "Field1"
    cmb2.ValueMember = "Field1"

and this for populating the cmb2 with values on page load:
VB
Dim ds As DataSet = SQL.PopcmbEquip(ojConn, BG) - sql statement : select field2 from tableB order by field 2

ojConn.Close()
If ds.Tables(0).Rows.Count > 0 Then
    Dim DT As New DataTable()
    DT = ds.Tables(0)
    cmb2.DataSource = DT
    cmb2.DisplayMember = "Field2"
   cmb2.ValueMember = "Field2"

I am getting error:
Cannot bind to the new value member.  Parameter name: value

I think the error is because I cannot assign two datasource and valuemember to one combo box :(

Any inputs will be greatly appreciated.
Thank you so much in advance.
Posted
Updated 16-Jun-15 1:31am
v2
Comments
Herman<T>.Instance 16-Jun-15 10:57am    
- And which OnChange event shows the error?

1 solution

If you want both SQL results bound to one combo box, simply use a UNION with your select statements:

SQL
select Field1 from tableA where field1 = cmb1.value
UNION
select field2 from tableB order by field 2


This should get you both queries in one table that you can bind to.

Brent
 
Share this answer
 
v2
Comments
serigraphie 17-Jun-15 7:28am    
Sorry Brent not the answer I am looking for :( thank you though

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900