Dual combo box binding problem (with master detail relation)

  • Thread starter Thread starter JC Voon
  • Start date Start date
J

JC Voon

Hi:

I have two combo boxes on screen that when one's selection is change
the
other's items will be updated to reflect the
change

dtMaster = ....
ds.Tables.Add(dtMaster)

dtDetail = ...
ds.Tables.Add(dtBranch)

rel = New DataRelation("MasterDetail", dtMaster.Columns("Code"),
dtDetail.Columns("Code"))
ds.Relations.Add(rel)

cboMaster.DataSource = ds.Tables("Master")
cboMaster.DisplayMember = "Name"
cboMaster.ValueMember = "Code"

cboDetail.DataSource = ds.Tables("Detail")
cboDetail.DisplayMember = "Name"
cboDetail.ValueMember = "Code"

Now, when the user changes the cboMaster, the cboDetail should show
only the record related to the cboMaster, but it show all !
How do i correct this?

Thanks
JCVoon
 
Hi,

Bind the second combobox to a dataview. Filter the results for the
second combobox in the selected value changed event of the first combobox.

Ken
---------------
Hi:

I have two combo boxes on screen that when one's selection is change
the
other's items will be updated to reflect the
change

dtMaster = ....
ds.Tables.Add(dtMaster)

dtDetail = ...
ds.Tables.Add(dtBranch)

rel = New DataRelation("MasterDetail", dtMaster.Columns("Code"),
dtDetail.Columns("Code"))
ds.Relations.Add(rel)

cboMaster.DataSource = ds.Tables("Master")
cboMaster.DisplayMember = "Name"
cboMaster.ValueMember = "Code"

cboDetail.DataSource = ds.Tables("Detail")
cboDetail.DisplayMember = "Name"
cboDetail.ValueMember = "Code"

Now, when the user changes the cboMaster, the cboDetail should show
only the record related to the cboMaster, but it show all !
How do i correct this?

Thanks
JCVoon
 
dtMaster = ....
ds.Tables.Add(dtMaster)

dtDetail = ...
ds.Tables.Add(dtBranch)

rel = New DataRelation("MasterDetail", dtMaster.Columns("Code"),
dtDetail.Columns("Code"))
ds.Relations.Add(rel)

cboMaster.DataSource = ds.Tables("Master")
cboMaster.DisplayMember = "Name"
cboMaster.ValueMember = "Code"

cboDetail.DataSource = ds.Tables("Master")
cboDetail.DisplayMember = "MasterDetail.Name"
cboDetail.ValueMember = "Code"
 
Ken Tucker:
Bind the second combobox to a dataview. Filter the results for the
second combobox in the selected value changed event of the first combobox.

Thanks for the reply. It work for me now, but the DataRelation object
become useless, then what is the purposes of the DataRelation object
if we still need to do a lot of code to filter out the record ?

Cheers
JCVoon
 
Rulin Hong:
dtMaster = ....
ds.Tables.Add(dtMaster)

dtDetail = ...
ds.Tables.Add(dtBranch)

rel = New DataRelation("MasterDetail", dtMaster.Columns("Code"),
dtDetail.Columns("Code"))
ds.Relations.Add(rel)

cboMaster.DataSource = ds.Tables("Master")
cboMaster.DisplayMember = "Name"
cboMaster.ValueMember = "Code"

cboDetail.DataSource = ds.Tables("Master")
cboDetail.DisplayMember = "MasterDetail.Name"
cboDetail.ValueMember = "Code"

Thank for your reply, actually i prefer this method, but my combo box
show "System.Data.DataRowView" in each record in the combo box,
instead of the column value, can u please tell me how to overcome this
problem ?

Thanks
JCVoon
 
Hi,

If you have 2 datagrids you can have a parent and child grid.

Ken
-------------------
Ken Tucker:
Bind the second combobox to a dataview. Filter the results for the
second combobox in the selected value changed event of the first combobox.

Thanks for the reply. It work for me now, but the DataRelation object
become useless, then what is the purposes of the DataRelation object
if we still need to do a lot of code to filter out the record ?

Cheers
JCVoon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top