We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ComboBox in master-detail relation.

Hi all! 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 // Dataset 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. B.I.

4 Replies

UE UESTC December 5, 2002 04:44 AM UTC

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.

IB Istvan Bagyura December 5, 2002 07:53 AM UTC

Hi! 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. Thanks! B.I.

UE UESTC December 8, 2002 04:02 AM UTC

Hi: 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.

IB Istvan Bagyura December 11, 2002 09:53 AM UTC

I did this. Thanks your replies. B.I.

Live Chat Icon For mobile
Up arrow icon