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

Recursively accessing parent rows from nested grid in GGC

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

4 Replies

ST stanleyj Syncfusion Team 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


JM Jay Mooney December 20, 2005 01:55 PM UTC

Works like a charm! Thank you.


JM Jay Mooney 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?


JM Jay Mooney 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?

Loader.
Live Chat Icon For mobile
Up arrow icon