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

Change expand collapse image of radgrid on the fly

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tiago
Top achievements
Rank 1
Tiago asked on 21 Sep 2018, 02:43 PM

Hi there, 

I am trying to change the expand/collapse of the radgrid on the fly. The reason is because I wanna change the icon when I do not have any item on the detail table for the respective Item, working as a visual cue.

Following is my code:

 

GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
            foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
            {
                foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
                {
                    if (**myBusinessLogic**)
                    {
                        nestedView.ExpandCollapseColumn.ButtonType = GridExpandColumnType.ImageButton;
                        nestedView.ExpandCollapseColumn.ExpandImageUrl = "../Resource/Image/CustomExpand.png";
                        nestedView.ExpandCollapseColumn.CollapseImageUrl = "../Resource/Image/CustomCollapse.png";
                    }
                }
            }

 

After running this code the icon remains the same. 

Thank you

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Sep 2018, 05:56 AM
Hello Tiago,

You can use the following approach to achieve this requirement:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/hierarchy/hiding-the-expand-collapse-images-when-no-records

Here are some key points:
1. Change the HierarchyLoadMode to either ServerBind or Client
2. Change the button type of the expand column to ImageButton:
<telerik:RadGrid ... MasterTableView-ExpandCollapseColumn-ButtonType="ImageButton">
3. Access the ImageButton when there are no child records using the approach demonstrate in the article given above, and change its ImageUrl property depending on your requirements.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Tiago
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or