473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dual combo box binding problem (with master detail relation)

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
Nov 21 '05 #1
5 6286
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
---------------
"JC Voon" <jc*******@yahoo.com> wrote in message
news:41***************@msnews.microsoft.com...
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
Nov 21 '05 #2
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"

Nov 21 '05 #3
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
Nov 21 '05 #4
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
Nov 21 '05 #5
Hi,

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

Ken
-------------------
"JC Voon" <jc*******@yahoo.com> wrote in message
news:41**************@msnews.microsoft.com...
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
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joăo Santa Bárbara | last post by:
Hi all i have a create a relation between two tables, and both of then have Autonumbers ( Sql ), since i have the Datarelation, i create a new record in the master table, and a few in the detail...
1
by: Juan | last post by:
I built a form that displays a master-detail relation ship, now i need to add a column to the datagrid displaying the master data, this column corresponds to the text name of a column stored in the...
3
by: Jane | last post by:
Hello, I am working on a windows application with C#. What I need is to display a list of data in 2nd combo box based on the selection of the 1st combo box. I used SqlCommand object and...
0
by: sagdude | last post by:
I have a master detail datatable and add a relation DataRelation relation = new DataRelation("PartNoRelation", Dt_Cart.Columns, Tbl_NearestCenters.Columns,false);...
7
by: erniej | last post by:
as per instructions in the walkthrough, I have managed to create a master/detail relationship between two datagrids. However I have a requirement to apply this to three datagrids and the third...
6
by: Brian Henry | last post by:
Here's an example of the code.. 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 (based on a relation) Private...
2
by: SoftWhiteDelgiht | last post by:
Help me. I am obviously stupid! :-) I am just starting out with VB.Net and am trying to do a simple master/detail form with a SqlServer backend. I have created a combo box which is to populate with...
4
by: Patrick | last post by:
Hi - I have a master/detail form with a combo box (AssetCode) on the master form which uses a query as its Row Source. I can choose a selection from the AssetCode combo box which fires an...
3
by: fstenoughsnoopy | last post by:
Ok the complete story. I have a Contact Table, Query and Form, that are used to input and store the contact info for customers. They have FirstName, LastName and Address as the primary key...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.