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.

Recursively accessing parent rows from nested grid in GGC

Thread ID:

Created:

Updated:

Platform:

Replies:

38820 Dec 19,2005 11:32 PM Dec 20,2005 03:33 PM Windows Forms 4
loading
Tags: GridControl
Jay Mooney
Asked On December 19, 2005 11:32 PM

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 05:39 AM

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 08:55 AM

Works like a charm! Thank you.

Jay Mooney
Replied On December 20, 2005 03:12 PM

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 03:33 PM

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?

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.

;