The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
STstanleyj 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
JMJay MooneyDecember 20, 2005 01:55 PM UTC
Works like a charm!
Thank you.
JMJay MooneyDecember 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?
JMJay MooneyDecember 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?