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

Removing Visible Columns in Hierarchy Grid Dynamically

Hello. I am a licensed user of Syncfusion EssentialGrid Version 8.4.0.10

I have used the online samples that came with the installation to setup a 3-Level Hierarchy grid. However, when I expand the parent and child tables I see columns that I don't want to see. I thought that I could hide the columns when the row was expanded, but the sample code below does not work:

protected void ggcAssess_RecordExpanded(object sender, RecordEventArgs e)
{
foreach (GridNestedTable nt in e.Record.NestedTables)
{
//Set AllowNew property for the nested tables
nt.ChildTable.ParentTableDescriptor.AllowNew = false;

//attempt to hide columns
if (nt.ChildTable.Name == "Standards")
{
nt.ChildTable.EngineTable.TableDescriptor.VisibleColumns.Remove("standard_section_code");
nt.ChildTable.EngineTable.TableDescriptor.VisibleColumns.Remove("standard_code");
}
else if (nt.ChildTable.Name == "Indicators")
{
nt.ChildTable.EngineTable.TableDescriptor.VisibleColumns.Remove("standard_code");
}
}
}


I am unclear which event I should use to hide child and grandchild columns dynamically. Can anyone help me please?


1 Reply

SN Sridhar N Syncfusion Team January 28, 2011 04:51 AM UTC

Hi Adrian,

Thanks for using Syncfusion Products.

Query 1 : "I have used the online samples that came with the installation to setup a 3-Level Hierarchy grid. However, when I expand the parent and child tables I see columns that I don't want to see. I thought that I could hide the columns when the row was expanded, but the sample code below does not work"

Your requirement to hide the childtable columns dynamically can be achieved by removing the visible columns from the child table in the recordexpanded event. Please refer the below code snippet.

[Codebehind-C#]

protected void GridGroupingControl1_RecordExpanded(object sender, Syncfusion.Grouping.RecordEventArgs e)
{
foreach (GridNestedTable nt in e.Record.NestedTables)
{
if (nt.ChildTable.Name == "MyChildTable")
{
nt.ChildTable.ParentTableDescriptor.VisibleColumns.Remove("ParentID");
}
else if (nt.ChildTable.Name == "MyChildTable1")
{
nt.ChildTable.ParentTableDescriptor.VisibleColumns.Remove("ChildID");
}
}
}


For your convenience, we have created a sample and the same can be downloaded from the following link.

Hierarchy-2136685208.zip

Please let us know your concerns.

Regards,
Sridhar.N




Loader.
Live Chat Icon For mobile
Up arrow icon