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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ComboBox in master-detail relation.

Thread ID:





1920 Dec 4,2002 01:00 PM UTC Dec 11,2002 09:53 AM UTC WinForms 4
Tags: FAQ
Istvan Bagyura
Asked On December 4, 2002 01:00 PM UTC

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.

Replied On 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.

Istvan Bagyura
Replied On 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.

Replied On 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.

Istvan Bagyura
Replied On December 11, 2002 09:53 AM UTC

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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon