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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Recursively accessing parent rows from nested grid in GGC

Thread ID:





38820 Dec 20,2005 04:32 AM UTC Dec 20,2005 08:33 PM UTC WinForms 4
Tags: GridControl
Jay Mooney
Asked On December 20, 2005 04:32 AM UTC

Hello, I am trying to find out how to access the parent rows for a table that is nested N deep in a GridGroupingControl. I looked in the Knowledgebase and found an article for accessing a detail record''s parent row. Element el = this.gridGroupingControl1.TableControl.Table.CurrentElement; if(el != null) { if(el is GridRecord) { Console.WriteLine("no parent row..."); } else if(el is GridNestedTable) { GridNestedTable gnt = el as GridNestedTable; GridNestedTable gnt1 = gnt; while(gnt1 != null && gnt1.ChildTable != null) { gnt = gnt1; gnt1 = gnt.ChildTable.ParentTable.CurrentElement as GridNestedTable; } DataRowView drv = gnt.ParentRecord.GetData() as DataRowView; Console.WriteLine(drv[1].ToString()); //show column 2 } } However, I tried to take this one step further, I wanted to access both the parent row, and it''s parent ( I have a ggc with 3 levels). When I tried to do the ParentRecord.ParentRecord, I got into trouble, it was null. So, I am curious how to use the object model to walk the tree in reverse from the innermostselection. Thank you. Jay

stanleyj [Syncfusion]
Replied On December 20, 2005 10:39 AM UTC

Hi Jay, This iterate function will return parent record for the given record. This is recursive till the top table. public Record iterate(Record r) { string tbl= r.ParentTableDescriptor.GetName(); GridTableDescriptor gt = this.gridGroupingControl1.GetTableDescriptor(tbl); if(gt.ParentTableDescriptor != null) { Record rec = r.ParentChildTable.ParentNestedTable.ParentRecord; return iterate(rec); } return r; } Record parentRecord; private void button1_Click(object sender, System.EventArgs e) { Element el= this.gridGroupingControl1.Table.GetInnerMostCurrentElement(); if(el!=null) { GridRecord rec=(GridRecord)el; if(rec!=null) parentRecord = iterate(rec); Console.WriteLine(parentRecord.Info); } } Let me know if this helps. Best regards, Stanley

Jay Mooney
Replied On December 20, 2005 01:55 PM UTC

Works like a charm! Thank you.

Jay Mooney
Replied On December 20, 2005 08:12 PM UTC

OK, follow up question: How do I map the indexes for the records from a Table to a NestedTable? Using the routine above, I can get the record position for selected record, and its ancestors. But, these record positions are only valid if you treat them as actual records. If you try to come back down into the grid using the NestedTable object, the record positions will be out of range. So, I''m looking for either an offset field in the nested table that tells me which records to grab, or a way to map my record positions. Does such a thing exist?

Jay Mooney
Replied On December 20, 2005 08:33 PM UTC

I think I found it: if (wtso.RecordIndex >= records.Count) { GridTable gt = this.GetTable(tableName); Record rec = gt.Records[wtso.RecordIndex]; wtso.MappedRecordIndex = records.IndexOf(rec); } It''s sort of ugly though, is there a more elegant solution?


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