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

RadGrid hide expand/collapse buttons

3 Answers 960 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cyber High
Top achievements
Rank 1
Cyber High asked on 04 Feb 2014, 10:17 PM
Hi.  I've attached an image of a hierarchical RadGrid 3 levels deep (Category-Subcategory-Standard).  I'm having a problem removing the useless expand/collapse button (or arrow) at the Standard (3rd) level.  I've used the following recursive function but it only goes 2 layers deep in removing the buttons as you can see in the image.  I'm not even sure why there is an expand/collapse button at the 3rd level because it is the innermost detail table.  Any advice as to how I could remove ALL expand/collapse buttons in the grid?  What am I missing?

Here is my code for creating the grid from the code behind.

            rgStandards = new RadGrid { ID = "rgStandards", EnableEmbeddedSkins = false, AutoGenerateColumns = false};
            rgStandards.PreRender += rgStandards_PreRender;
            StandardsSet.Tables[0].TableName = "categories";
            StandardsSet.Tables[1].TableName = "subcategories";
            StandardsSet.Tables[2].TableName = "standards";


            //Standard Categories
            rgStandards.MasterTableView.DataMember = "categories";
            rgStandards.MasterTableView.DataKeyNames = new string[] { "category" };
            rgStandards.MasterTableView.HierarchyDefaultExpanded = true;
            rgStandards.AllowPaging = false;
            GridBoundColumn boundColumn;
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "category";
            boundColumn.HeaderText = "Category";
            rgStandards.MasterTableView.Columns.Add(boundColumn);

            //Standard Subcategories
            GridTableView gtvSubcategories = new GridTableView(rgStandards);
            gtvSubcategories.DataMember = "subcategories";
            gtvSubcategories.DataKeyNames = new string[] { "subcategory" };
            GridRelationFields grfSubcategories = new GridRelationFields();
            grfSubcategories.MasterKeyField = "category";
            grfSubcategories.DetailKeyField = "category";
            gtvSubcategories.ParentTableRelation.Add(grfSubcategories);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "subcategory";
            boundColumn.HeaderText = "Subcategory";
            gtvSubcategories.Columns.Add(boundColumn);
            rgStandards.MasterTableView.DetailTables.Add(gtvSubcategories);

            //Standard Details
            GridTableView gtvStandards = new GridTableView(rgStandards);
            gtvStandards.DataMember = "standards";
            gtvStandards.DataKeyNames = new string[] { "standardText" };
            GridRelationFields grfStandards = new GridRelationFields();
            grfStandards.MasterKeyField = "subcategory";
            grfStandards.DetailKeyField = "subcategory";
            gtvStandards.ParentTableRelation.Add(grfStandards);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "standardText";
            boundColumn.HeaderText = "Standard";
            gtvStandards.Columns.Add(boundColumn);
            gtvSubcategories.DetailTables.Add(gtvStandards);
            gtvSubcategories.HierarchyDefaultExpanded = true;

            rgStandards.DataSource = StandardsSet;
            rgStandards.DataBind();

And here is my recursive function for removing the expand/collapse buttons:

        protected void rgStandards_PreRender(object sender, EventArgs e) {
            HideExpandColumnRecursive(rgStandards.MasterTableView);
        }

        public void HideExpandColumnRecursive(GridTableView tableView) {
            GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
            foreach (GridNestedViewItem nestedViewItem in nestedViewItems) {
                foreach (GridTableView nestedView in nestedViewItem.NestedTableViews) {
                    TableCell cell = nestedView.ParentItem["ExpandColumn"];
                    cell.Controls[0].Visible = false;
                    if (nestedView.HasDetailTables) {
                        HideExpandColumnRecursive(nestedView);
                    }
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Feb 2014, 06:34 AM
Hi,

This is not an expected behavior. Please check  this demo which shows 3 Level hierarchy (http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx), also please make sure you have created the RadGrid properly in the Init Event which is discussed here (http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html). 
In order to hide the ExpandCollapse image you can try the following code snippet:

C#:
//Standard Details
GridTableView gtvStandards = new GridTableView(rgStandards);
gtvStandards.ExpandCollapseColumn.Visible = false;

Thanks,
Shinu.
mkk09
Top achievements
Rank 1
commented on 06 Jan 2023, 12:40 PM

Can you please give me any link of the Same example for WPF MVVVM?
0
Cyber High
Top achievements
Rank 1
answered on 06 Feb 2014, 05:06 PM
It looks like when the radgrid is constrained to a smaller div, horizontally, it forces those expand/collapse buttons appear.  Here is a screenshot from a larger div and the exact same radgrid.  Notice the expand/collapse buttons are not present.  This may be a bug but I at least wanted to make you aware of it.  Thank you very much for responding.
0
Viktor Tachev
Telerik team
answered on 11 Feb 2014, 10:47 AM
Hi,

The issue you are experiencing seems rather strange. The GridExpandColumn should be visible only when there are detail tables in the TableView. There should be no expand/collapse arrow in the innermost hierarchy level.

In the code you provided I noticed that you are using simple data binding (with the DataBind() method). Note that this type of binding is not recommended to be used when you have hierarchical structure for RadGrid as stated in this article. When having hierarchy relations in RadGrid it is recommended to implement advanced data binding by using either declarative data source or handling NeedDataSource event.

If after setting advanced data binding for the grid the issue is still observed we would need more information in order to try replicating the problem locally. Would you elaborate more on the scenario you have? What event are you using to create the grid? I would also appreciate it if you could share the full markup with the related code-behind for RadGrid. This would enable us to investigate the problem locally and provide an appropriate solution.


Regards,
Viktor Tachev
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Cyber High
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Cyber High
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or