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

Hiding column in hierarchical grid: formatting issues

2 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 13 Jul 2010, 04:17 PM
I have a hierarchical grid where the parent and the children all use the same column headers such as follows.  Everything looks fine when I show the Action column.  When I hide the Action column, however, the column's contents remain in the child rows (e.g., where the Type is Child in the example below) and the formatting is messed up (see below).

ActionColumn.Visible = true;
 
ID  Parent  Name    Type     Action
1   -       Note    Parent   O:E:D
2   1       Reply   Child    O:E
3   2       Reply   Child    O:E
4   -       Note    Parent   O:E:D
 
ActionColumn.Visible = false;
 
ID  Parent     Name       Type    
1   -          Note       Parent  
2   1       Reply      Child    O:E
3   2       Reply      Child    O:E
4   -          Note       Parent  

I'm setting the  grdNotes.Columns.FindByUniqueName("Actions").Visible = ShowActionColumn (where ShowActionColumn is a bool property set by the user preferences) in the Page_Load event. 

What else needs to be done to hide the contents of the child row's column contents?  (I've already tried setting toolbar.visible=false, but to no avail.)

FWIW, here's the definition of the grid:

<telerik:RadGrid ID="grdNotes" runat="server" OnColumnCreated="grdNotes_ColumnCreated"
    OnItemCreated="grdNotes_ItemCreated" OnItemDataBound="grdNotes_ItemDataBound"
    OnNeedDataSource="grdNotes_NeedDataSource" OnPreRender="grdNotes_PreRender" AutoGenerateColumns="false"
    SkinID="HierarchicalGrid" GridLines="None" AllowPaging="false" AllowCustomPaging="True"
    ShowStatusBar="True" EnableLinqExpressions="True" PageSize="20" Width="100%">
    <HeaderContextMenu EnableTheming="True">
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
    </HeaderContextMenu>
    <ClientSettings Selecting-AllowRowSelect="true" Resizing-AllowColumnResize="true">
        <ClientEvents OnRowSelected="RowSelected" OnRowContextMenu="NoteContextMenu" OnRowCreated="RowCreated"
            OnRowDblClick="grdNotes_OnRowDblClick" OnColumnResized="ResizeAllColumns" OnGridCreated="PageLoad" />
    </ClientSettings>
    <PagerStyle Position="Bottom" AlwaysVisible="True" Mode="NextPrevAndNumeric" Wrap="False"
        BackColor="White" Font-Size="Large" />
    <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="true"
        DataKeyNames="Id,ParentId,Token,IsRoot,Replies,NoteCreator" ClientDataKeyNames="Id,ParentId,Token,IsRoot,Replies,NoteCreator"
        NoDetailRecordsText="" EnableNoRecordsTemplate="False" Width="100%">
        <SelfHierarchySettings ParentKeyName="ParentId" KeyName="Id" MaximumDepth="20" />
        <Columns>
            <telerik:GridBoundColumn DataField="Id" HeaderText="Id" SortExpression="Id" UniqueName="Id"
                ReadOnly="True" HeaderStyle-Width="10%">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Title" HeaderText="Title" SortExpression="Title"
                UniqueName="Title" HeaderStyle-Width="20%" />
            <telerik:GridBoundColumn DataField="Body" HeaderText="Body" SortExpression="Body"
                UniqueName="Body" HeaderStyle-Width="40%" />
            <telerik:GridBoundColumn DataField="CreatedBy" HeaderText="Created By" SortExpression="CreatedBy"
                UniqueName="CreatedBy" HeaderStyle-Width="15%" />
            <telerik:GridBoundColumn DataField="CreatedDate" HeaderText="Created On" SortExpression="CreatedDate"
                UniqueName="CreatedOn" HeaderStyle-Width="15%" />
            <telerik:GridBoundColumn DataField="ParentId" HeaderText="Parent Id" SortExpression="ParentId"
                UniqueName="ParentId" Visible="false" />
            <telerik:GridBoundColumn DataField="Token" HeaderText="Token" SortExpression="Token"
                UniqueName="Token" Visible="true" />
            <telerik:GridBoundColumn DataField="IsRoot" HeaderText="IsRoot" SortExpression="IsRoot"
                UniqueName="IsRoot" Visible="false" />
            <telerik:GridBoundColumn DataField="Replies" HeaderText="Replies" SortExpression="Replies"
                UniqueName="Replies" Visible="false" />
            <telerik:GridBoundColumn DataField="NoteCreator" HeaderText="NoteCreator" SortExpression="NoteCreator"
                UniqueName="NoteCreator" Visible="false" />
            <telerik:GridTemplateColumn UniqueName="Actions" HeaderStyle-Width="150" HeaderText="Actions">
                <ItemTemplate>
                    <telerik:RadToolBar ID="rtbNoteActions" runat="server" SkinID="ActionToolbar" OnButtonClick="NotesGridToolbarButtonClicked"
                        OnClientButtonClicking="NoteActionToolbarClicking">
                        <Items>
                            <telerik:RadToolBarButton Text="Properties" CommandName="Properties" ImageUrl="~/Images/page_view.gif" />
                            <telerik:RadToolBarButton Text="Reply" CommandName="Reply" ImageUrl="~/Images/page_edit.gif" />
                            <telerik:RadToolBarButton Text="Security" CommandName="Security" ImageUrl="~/Images/shield16.gif" />
                            <telerik:RadToolBarButton Text="Delete" CommandName="Delete" ImageUrl="~/Images/delete16.gif" />
                        </Items>
                    </telerik:RadToolBar>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <FilterMenu EnableTheming="True">
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
    </FilterMenu>
</telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
walter verhoeven
Top achievements
Rank 1
answered on 14 Jul 2010, 03:07 PM
Hi Matt

I have the exact same issue, however I have a SelfHierarchySettings and when I go over 2 levels I get a mess I hope there is a fix, I will let you know if I find it as I am working on it now.

Regards

Walter
0
Daniel
Telerik team
answered on 19 Jul 2010, 12:22 PM
Hi guys,

You can hide the desired column recursively:
public void HideColumnRecursive(GridTableView tableView, string ColumnName)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    tableView.GetColumn(ColumnName).Visible = false;
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
        foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
            if (nestedView.HasDetailTables)
                HideColumnRecursive(nestedView, ColumnName);
}

HideColumnRecursive(RadGrid1.MasterTableView, "FirstName");

I hope this helps.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
walter verhoeven
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or