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

DataGrid master-detail causing problems - Please help!

Please help! I am desparate. I need to deliver this application today but, since I implemented a single DataRelation and added it to my DataSet, my DataGrids are now ignoring all DefaultView settings. Why? I have a filter function that allows the user to filter the results by setting certain criteria. Prior to implementing the DataRelation, setting the filter always worked. Here is some of my code: //Synchronize an XML document with the DataSet xmlPlan = new System.Xml.XmlDataDocument(); xmlPlan.DataSet.ReadXmlSchema Application.ExecutablePath.Substring(0, Application.ExecutablePath.IndexOf("CWPlanViewer.exe")) + "plan.xsd"); dsPlan = xmlPlan.DataSet; dsPlan.AcceptChanges(); // Add a dataRelation dsPlan.Relations.Add("PlanDrawings", dsPlan.Tables ["Plan"].Columns["planId"], dsPlan.Tables ["Drawing"].Columns["planId"]); //Set DefaultView settings for master table dsPlan.Tables["Plan"].DefaultView.AllowDelete = false; dsPlan.Tables["Plan"].DefaultView.AllowNew = false; dsPlan.Tables["Plan"].DefaultView.Sort = "name"; // Set data bindings on master datagird dgPlans.DataSource = dsPlan; dgPlans.DataMember = "Plan"; //Set DefaultView settings on detail table dsPlan.Tables["Drawing"].DefaultView.AllowDelete = false; dsPlan.Tables["Drawing"].DefaultView.AllowEdit = false; dsPlan.Tables["Drawing"].DefaultView.AllowNew = false; dsPlan.Tables["Drawing"].DefaultView.Sort = "sort, drawType"; // Set data bindings on detail datagrid dgDraw.DataSource = dsPlan; dgDraw.DataMember = "Plan.PlanDrawings"; //When a user chooses criteria and clicks a button, this code gets executed. ....... dsPlan.Tables["Plan"].DefaultView.RowFilter = criteria.ToString(); dgPlans.CaptionText = dsPlan.Tables ["Plan"].DefaultView.Count + " plans found"; Now, when the criteria gets set and the button gets clicked, the RowFilter does get set correctly and the CaptionText is correctly set to dispaly the number of records the filter criteria should find. In my testing, I set the criteria such that it will result in 1 record. I click the button. The CaptionText gets set to "1 Plans Found" but the DataGrid is still showing all records. This used to work. Why would adding a DataRelation stop all of this from working? Further more, all the other DefaultView settings are being ignored by the DataGrids too. I have tried using a DataViewManager and that also did not solve my problem. Addendum: I have now found that if I change the way I set the data bindings that I can solve one problem but create another. I change the way I set the data bindings on the master DataGrid from: dgPlans.DataSource = dsPlan; dgPlans.DataMember = "Plan"; to: dgPlans.DataSource = dsPlan.Tables["Plan"]; Now the DataGrid recognizes the DataView settings BUT now the detail DataGrid is no longer recognizing the relationship with the master DataGrid so that when I select a record in the master DataGrid, the detail DataGrid remains unchanged. It was explained to me yesterday that this is because the two DataGrids each have their own Binding Manager due to the two different ways in which I set the data bindings. So I have tried the following ways to set the data bindings on the detail DataGrid: //This doesn't work because it is apparently creating a separate binding manager from the that of the master DataGrid. dgDraw.DataSource = dsPlan; dgDraw.DataMember = "Plan.PlanDrawings"; // This causes an System.ArgumentNullException: dgDraw.DataSource = dsPlan.Tables["Plan.PlanDrawings"]; // This results in all records in the detail table being shown (ignoring the master-detail relationship.) dgDraw.DataSource = dsPlan.Tables["Drawing"]; // This also results in all records in the detail table being shown (ignoring the master-detail relationship.) dgDraw.DataSource = dsPlan.Tables["Drawing"].Relations["PlanDrawings"].ChildTable; // This causes a System.Exception with additional information of : Complex DataBinding accepts as a data source either an IList or an IListSource. dgDraw.DataSource = dsPlan.Relations["PlanDrawings"]; // This also causes a System.Exception with additional information of : Complex DataBinding accepts as a data source either an IList or an IListSource. dgDraw.DataSource = dsPlan.Tables["Drawing"].Relations["PlanDrawings"]; As I previously mentioned I have also unsuccessfully tried using a DataViewManager. I got no errors but the DefaultView settings were being ignored. How do I set the detail DataGrid's data bindings so that the DataGrid will recognize the master-detail relationship AND the detail table's DefaultView settings??? Thanks, Darwin

2 Replies

AD Administrator Syncfusion Team August 8, 2003 03:24 AM UTC

> Please help! I am desparate. I need to deliver this application today but, since I implemented a single DataRelation and added it to my DataSet, my DataGrids are now ignoring all DefaultView settings. Why? I have a filter function that allows the user to filter the results by setting certain criteria. Prior to implementing the DataRelation, setting the filter always worked. Here is some of my code: > > //Synchronize an XML document with the DataSet > xmlPlan = new System.Xml.XmlDataDocument(); > xmlPlan.DataSet.ReadXmlSchema Application.ExecutablePath.Substring(0, > Application.ExecutablePath.IndexOf("CWPlanViewer.exe")) + "plan.xsd"); > dsPlan = xmlPlan.DataSet; > dsPlan.AcceptChanges(); > > // Add a dataRelation > dsPlan.Relations.Add("PlanDrawings", dsPlan.Tables > ["Plan"].Columns["planId"], dsPlan.Tables > ["Drawing"].Columns["planId"]); > > //Set DefaultView settings for master table > dsPlan.Tables["Plan"].DefaultView.AllowDelete = false; > dsPlan.Tables["Plan"].DefaultView.AllowNew = false; > dsPlan.Tables["Plan"].DefaultView.Sort = "name"; > > // Set data bindings on master datagird > dgPlans.DataSource = dsPlan; > dgPlans.DataMember = "Plan"; > > //Set DefaultView settings on detail table > dsPlan.Tables["Drawing"].DefaultView.AllowDelete = false; > dsPlan.Tables["Drawing"].DefaultView.AllowEdit = false; > dsPlan.Tables["Drawing"].DefaultView.AllowNew = false; > dsPlan.Tables["Drawing"].DefaultView.Sort = "sort, > drawType"; > > // Set data bindings on detail datagrid > dgDraw.DataSource = dsPlan; > dgDraw.DataMember = "Plan.PlanDrawings"; > > > //When a user chooses criteria and clicks a button, this code gets executed. > ....... > dsPlan.Tables["Plan"].DefaultView.RowFilter = > criteria.ToString(); > dgPlans.CaptionText = dsPlan.Tables > ["Plan"].DefaultView.Count + " plans found"; > > Now, when the criteria gets set and the button gets clicked, the RowFilter does get set correctly and the CaptionText is correctly set to dispaly the number of records the filter criteria should find. In my testing, I set the criteria such that it will result in 1 record. I click the button. The CaptionText gets set to "1 Plans > Found" but the DataGrid is still showing all records. > This used to work. Why would adding a DataRelation stop all of this from working? Further more, all the other DefaultView settings are being ignored by the DataGrids too. I have tried using a DataViewManager and that also did not solve my problem. > > Addendum: > I have now found that if I change the way I set the data bindings that I can solve one problem but create another. > > I change the way I set the data bindings on the master DataGrid from: > dgPlans.DataSource = dsPlan; > dgPlans.DataMember = "Plan"; > to: > dgPlans.DataSource = dsPlan.Tables["Plan"]; > > Now the DataGrid recognizes the DataView settings BUT now the detail DataGrid is no longer recognizing the relationship with the master DataGrid so that when I select a record in the master DataGrid, the detail DataGrid remains unchanged. It was explained to me yesterday that this is because the two DataGrids each have their own Binding Manager due to the two different ways in which I set the data bindings. So I have tried the following ways to set the data bindings on the detail DataGrid: > > //This doesn't work because it is apparently creating a separate binding manager from the that of the master DataGrid. > dgDraw.DataSource = dsPlan; > dgDraw.DataMember = "Plan.PlanDrawings"; > > // This causes an System.ArgumentNullException: > dgDraw.DataSource = dsPlan.Tables["Plan.PlanDrawings"]; > > // This results in all records in the detail table being shown (ignoring the master-detail relationship.) > dgDraw.DataSource = dsPlan.Tables["Drawing"]; > > // This also results in all records in the detail table being shown (ignoring the master-detail relationship.) > dgDraw.DataSource = dsPlan.Tables["Drawing"].Relations["PlanDrawings"].ChildTable; > > // This causes a System.Exception with additional > information of : Complex DataBinding accepts as a data source either an IList or an IListSource. > dgDraw.DataSource = dsPlan.Relations["PlanDrawings"]; > > // This also causes a System.Exception with additional information of : Complex DataBinding accepts as a data source either an IList or an IListSource. > dgDraw.DataSource = dsPlan.Tables["Drawing"].Relations["PlanDrawings"]; > > As I previously mentioned I have also unsuccessfully tried > using a DataViewManager. I got no errors but the > DefaultView settings were being ignored. > > How do I set the detail DataGrid's data bindings so that the DataGrid will recognize the master-detail relationship AND the detail table's DefaultView settings??? > > Thanks, > Darwin > > >


DS dsfasdf March 1, 2004 02:07 PM UTC

i have the same problem; can anyone help????

Loader.
Up arrow icon