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
close icon

GGC: Count ChildRecords

Hi! I have a parentTable (''idParent'',''NameParent'') and a childTable (''idChild'', ''idParent'', ''NameChild''). The childTable.idParent is the ForeignKey of parentTable.idParent. It''s a 1:n - Relation. Now in a GGC I set the DataSource to parentTable in order to display the parentTable''s NameParent. In a second column I want to display the number of related records fom the childTable. How can I do this in an easy way? Regards Falk

13 Replies

AD Administrator Syncfusion Team July 11, 2006 08:03 PM UTC

Hi Falk, This can be achieved by handling the TableControlDrawCellDisplayText event. In the event, the second column in the parent table is assigned with the child count using GetChildCount method of the respective record. The following is the demo sample. Sample : GGC_ForeignKey Best regards, Madhan


AD Administrator Syncfusion Team July 12, 2006 05:01 PM UTC

Hi! Unfortunately your sample doesn''t really work. Change the number of rows in any table. The counted children will be 4 in every case. I have the same behavior in my application - and I have up to 100 ChildRecords. Can you solve the problem? Regards Falk


AD Administrator Syncfusion Team July 12, 2006 10:40 PM UTC

Hi Falk, You can use the r.NestedTables[0].ChildTable.Records.Count instead of r.GetChildCount method to get the number of child records. I hope it helps to solve your issue. Kindly let us know if you need any further assistance. Best regards, Madhan


AD Administrator Syncfusion Team July 13, 2006 05:14 PM UTC

Ok, this seems to work. But there are still two suggestions: 1.: At the moment I''m working with a databound column, because for an unbound column the ggc_TableControlDrawCellDisplayText seems not to be called. The problem is: when I type in a new value in the AddNewRecord-Row, the underlying data is displayed. Is there a way to work with an unbound column? 2.: I''d like to hide the Plusminus-Button. But when I set the ShowRecordPlusMinus to false, the nested table is automaticly expanded. I want to keep it hidden. (I never want to display the Childtable). How can I realize tis behavior? Regards Falk


AD Administrator Syncfusion Team July 13, 2006 11:16 PM UTC

Hi Falk, The issue 1 can be by achieved by handling the QueryCellStyleInfo event. The following is the code snippet >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { Element el = e.TableCellIdentity.Table.DisplayElements[e.TableCellIdentity.RowIndex]; if(e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) { if(el != null && el.ParentChildTable.Name == "ParentTable" && el.Kind == DisplayElementKind.Record) { Record r = el.GetRecord(); if(r.GroupLevel == 0 && r != null && e.TableCellIdentity.Column.Name == "ChildCount") // ChildCount is an unbound column name { e.Style.CellValue = r.NestedTables[0].ChildTable.Records.Count.ToString(); } } } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> The issue 2 can be achieved by handling the QueryCellStyleInfo event and making the RecordPlusMinus cell as static celltype. Here is the KB article explains a way to hide the nested table http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=311 Best regards, Madhan


AD Administrator Syncfusion Team July 14, 2006 05:06 PM UTC

Hi! Just one last wish: The PlusMinusButton is gone now - but it left a white filled rectangle. Is there a possibility to hide this (e. g. setting it''s width = 0 or something else)? Regards Falk


AD Administrator Syncfusion Team July 17, 2006 10:28 AM UTC

No idea? I''d like to display the first column like a normal column, without a PlusMinus-Cell, without a nested table. Regards Falk


AD Administrator Syncfusion Team July 17, 2006 10:51 AM UTC

Hi Falk, Try setting the below property. this.gridGroupingControl1.TableOptions.ShowRecordPlusMinus = false; Regards, Rajagopal


AD Administrator Syncfusion Team July 17, 2006 11:42 AM UTC

Hi! I tried this. But now the nested table is shown automatically (expanded). But I don''t want to show it. What I want is: 1st Column: a record. 2nd Column: the number of related child-records in the childtable (1:n - relation). I don''t want to see the nested table and I don''t want to see the PlusMinus-Button. Is there any way to implement this behavior? Best Regards Falk


AD Administrator Syncfusion Team July 17, 2006 01:01 PM UTC

Hi Falk, Please try the code below in the QueryCellStyleInfo event of the gridgroupingcontrol, see if this helps. private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record) { Record rec = (Record) e.TableCellIdentity.DisplayElement.ParentRecord; if(rec.NestedTables[0].FilteredRecords.Count >= 0) { e.Style.CellType = "Static"; e.Style.Borders.Bottom = new GridBorder(this.gridGroupingControl1.TableModel.Options.DefaultGridBorderStyle); e.Style.Enabled = false; } } } // Form Load this.gridGroupingControl1.TableOptions.ShowRecordPlusMinus = true; Thanks, Rajagopal


AD Administrator Syncfusion Team July 17, 2006 03:07 PM UTC

Hi again! The displayed text is still indented. And the space (where former the PlusMinusButton was situated) is always white (even if the data-cell has another background-color). Any other suggestions? Regards Falk


AD Administrator Syncfusion Team July 18, 2006 10:00 AM UTC

Hi Falk, Please add the code below in the Form_Load, this will help you in achieving the desired behavior. this.gridGroupingControl1.TableOptions.ShowRecordPlusMinus = true; this.gridGroupingControl1.TableOptions.ShowTableIndent = false; Thanks, Rajagopal


AD Administrator Syncfusion Team July 18, 2006 03:10 PM UTC

Yippee! That''s it! I''ve spent days to find this solution - and now such a simple solution! Thanks a lot! Best Regards Falk

Loader.
Live Chat Icon For mobile
Up arrow icon