This is a migrated thread and some comments may be shown as answers.

[Solved] Can I toggle a self-referencing hierarchy on and off?

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 21 Aug 2013, 03:58 PM
Just as the title says, I want to be able to turn the self-referencing hierarchy on and off. I have a RadGrid of orders that I am creating the structure for in the code behind file, and a RadToolBar with a button for toggling the hierarchy. There are other buttons on the toolbar that I am using client-side script to respond to.

Code to build the grid structure.
private void InitializeGrid()
{
    try
    {
        // add columns
        Telerik.Web.UI.GridBoundColumn boundColumn = new Telerik.Web.UI.GridBoundColumn();
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "OrderId";
        boundColumn.UniqueName = "OrderId";
        boundColumn.HeaderText = "Order Id";
        boundColumn.DataType = typeof(System.Guid);
        boundColumn.Display = false;
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "Locked";
        boundColumn.UniqueName = "Locked";
        boundColumn.HeaderText = "Locked";
        boundColumn.DataType = typeof(System.Boolean);
        boundColumn.Display = false;
 
        Telerik.Web.UI.GridImageColumn imageColumn = new Telerik.Web.UI.GridImageColumn();
        uxOrderListControl.MasterTableView.Columns.Add(imageColumn);
        imageColumn.UniqueName = "LockImage";
        imageColumn.HeaderText = "L";
 
        imageColumn = new Telerik.Web.UI.GridImageColumn();
        uxOrderListControl.MasterTableView.Columns.Add(imageColumn);
        imageColumn.UniqueName = "A";
        imageColumn.HeaderText = "A";
 
        imageColumn = new Telerik.Web.UI.GridImageColumn();
        uxOrderListControl.MasterTableView.Columns.Add(imageColumn);
        imageColumn.UniqueName = "E";
        imageColumn.HeaderText = "E";
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "OrderType";
        boundColumn.UniqueName = "OrderType";
        boundColumn.HeaderText = "Type";
        boundColumn.DataType = typeof(System.String);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "CurrentOrderId";
        boundColumn.UniqueName = "CurrentOrderId";
        boundColumn.HeaderText = "Number";
        boundColumn.DataType = typeof(System.String);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "OrderDate";
        boundColumn.DataFormatString = "{0:d}";
        boundColumn.UniqueName = "OrderDate";
        boundColumn.HeaderText = "Date";
        boundColumn.DataType = typeof(System.DateTime);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "Total";
        boundColumn.DataFormatString = "{0:c}";
        boundColumn.UniqueName = "Total";
        boundColumn.HeaderText = "Total";
        boundColumn.DataType = typeof(System.Decimal);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "BillToName";
        boundColumn.UniqueName = "BillToName";
        boundColumn.HeaderText = "Bill To Name";
        boundColumn.DataType = typeof(System.String);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "SoldToName";
        boundColumn.UniqueName = "SoldToName";
        boundColumn.HeaderText = "Sold To Name";
        boundColumn.DataType = typeof(System.String);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "Lookup";
        boundColumn.UniqueName = "Lookup";
        boundColumn.HeaderText = "Lookup";
        boundColumn.DataType = typeof(System.String);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "NeedToEdi";
        boundColumn.UniqueName = "NeedToEdi";
        boundColumn.HeaderText = "Need To EDI";
        boundColumn.DataType = typeof(System.Boolean);
 
        boundColumn = new Telerik.Web.UI.GridBoundColumn();
        uxOrderListControl.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "ReferralInvoiceId";
        boundColumn.UniqueName = "ReferralInvoiceId";
        boundColumn.HeaderText = "Ref ID";
        boundColumn.DataType = typeof(System.Guid);
 
        uxOrderListControl.MasterTableView.DataKeyNames = new string[] { "OrderId", "ReferralInvoiceId" };
 
        if (_hierarchical)
        {
            uxOrderListControl.ClientSettings.AllowExpandCollapse = true;
            uxOrderListControl.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
            uxOrderListControl.MasterTableView.HierarchyDefaultExpanded = true;
            uxOrderListControl.MasterTableView.SelfHierarchySettings.ParentKeyName = "ReferralInvoiceId";
            uxOrderListControl.MasterTableView.SelfHierarchySettings.KeyName = "OrderId";
            uxOrderListControl.MasterTableView.SelfHierarchySettings.MaximumDepth = 2;
        }
    }
    catch
    {
        throw;
    }
}
#endregion

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 26 Aug 2013, 08:44 AM
Hello Bruce,

In order to turn off the self-referencing hierarchy you will need to set all default values to each of the properties in the SelfHierarchySettings and then rebind the grid as shown below. You could execute the code in the RadToolBar button click event handler.
uxOrderListControl.MasterTableView.SelfHierarchySettings.ParentKeyName = string.Empty;
uxOrderListControl.MasterTableView.SelfHierarchySettings.KeyName = string.Empty;
uxOrderListControl.MasterTableView.SelfHierarchySettings.MaximumDepth = 10;
uxOrderListControl.Rebind();

Regards,
Antonio Stoilkov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or