I have some problems with databinding with combo boxes in master-detail relation. ( And I can do master detail data binding with two grids )
I would like to show a form with a combobox and a datagrid.
The combobox contains the master data and the datagrid contains the details.
I bound the data both components, but if the combobox's value changes the grid does nothing.
It works fine with two datagrids so I can't figure out what's wrong with it.
Here is my code:
// MASTER - DETAIL Client - Site
this.ds = new DataSet() ;
// master data adapter
this.adClient = newSqlDataAdapter( " SELECT * FROM client " , ConnFactory.conn ) ;
adClient.Fill( ds , "tClient" ) ;
// client data adapter
this.adSite = new SqlDataAdapter( " SELECT * FROM job_site " , ConnFactory.conn ) ; ;
adSite.Fill( ds , "tSite" ) ;
// data relation
DataRelation rel = new DataRelation( "rel_client_site" , ds.Tables[ "tClient" ] .Columns[ "ID" ] , ds.Tables[ "tSite" ].Columns[ "client_ID" ] ) ;
ds.Relations.Add( rel ) ;
// DATA BINDING
cbClient.DataSource = ds.Tables[ "tClient" ] ;
cbClient.DisplayMember = "ID" ;
cbClient.ValueMember = "ID" ;
this.gridSites.DataSource = ds ;
this.gridSites.SetDataBinding( ds , "tClient.rel_client_site" ) ;
Pls help me to solve the problem.
I suggeste you to use the "DataRow.GetChildRows()"
method to retrieve the detail table when the ComboBox's selected index has changed.
You have created a relation between the two table.
Based on this condition, you can use the "GetChildRows()" method to get a table which includs all the child rows, so you can bind this table to you datagrid.
IBIstvan BagyuraDecember 5, 2002 02:53 AM
I've tried it but it can't solve my problem. ( but I solved it in another but very ugly way.)
I'd like to get to know the "common way" of this process. Pls write me if you know.
UEUESTCDecember 7, 2002 11:02 PM
I think you can't implement it in a "none-code" way.
I suggest you retrieve everytime the ComboBox's selected index changed, that's a common way.
write a SQL with parameters, when the selected index changed, get the key value, assign to the SQL parameters, then retrieve and rebind.