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

GGC: Count ChildRecords

Thread ID:

Created:

Updated:

Platform:

Replies:

46354 Jul 11,2006 02:23 PM Jul 18,2006 11:10 AM Windows Forms 13
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On July 11, 2006 02:23 PM

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

Administrator [Syncfusion]
Replied On July 11, 2006 04:03 PM

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

Administrator [Syncfusion]
Replied On July 12, 2006 01:01 PM

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

Administrator [Syncfusion]
Replied On July 12, 2006 06:40 PM

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

Administrator [Syncfusion]
Replied On July 13, 2006 01:14 PM

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

Administrator [Syncfusion]
Replied On July 13, 2006 07:16 PM

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

Administrator [Syncfusion]
Replied On July 14, 2006 01:06 PM

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

Administrator [Syncfusion]
Replied On July 17, 2006 06:28 AM

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

Administrator [Syncfusion]
Replied On July 17, 2006 06:51 AM

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

Administrator [Syncfusion]
Replied On July 17, 2006 07:42 AM

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

Administrator [Syncfusion]
Replied On July 17, 2006 09:01 AM

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

Administrator [Syncfusion]
Replied On July 17, 2006 11:07 AM

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

Administrator [Syncfusion]
Replied On July 18, 2006 06:00 AM

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

Administrator [Syncfusion]
Replied On July 18, 2006 11:10 AM

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

CONFIRMATION

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.

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.

;