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

Show/Hide Column(s) in Hierarchy

3 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 04 Apr 2011, 11:04 PM
Hi,

I have a grid hiarchy as follows:

Categories
.....Products
..........Order Details

Each table has exactly one row.  Initially all colums are set to:
     col.IsVisible = false

I call the function below to show a particular column.  In the Categories column I can show all columns.  In Product and Order Details I can only show one column even though I am setting the col.IsVisible = true to other columns in the row.

Thanks
Rich;


public static void ShowGridColumn(RadGridView grid, String columnName)
        {
            IEnumerable<GridViewRow> rows = 
                grid.ChildrenOfType<GridViewRow>().Where(s => s.Item != null);
            foreach (GridViewRow row in rows)
            {
                var dataControl = row.GridViewDataControl;
                foreach (GridViewColumn col in dataControl.Columns)
                {
                    if (col.UniqueName == columnName)
                    {
                        col.IsVisible = true;
                        return;
                    }
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 05 Apr 2011, 08:21 AM
Hello Richard Harrigan,

May you try to remove the "return;" statement in the code above ? Furthermore, please keep in mind that if the child grid is not visualized (opened), it is not yet created and you cannot set its columns' visibility to "True". Only if the inner grids are opened, the columns will be available. 

 

Regards,
Maya
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
0
Richard Harrigan
Top achievements
Rank 1
answered on 05 Apr 2011, 08:07 PM
Hi,

The return was ok since I am only trying to make one column visible at a time based on user guidance.  I think there may be a very subtle bug in the grid code.  The situation is as follows:

- Using a hierachy grid
- All columns are set to  IsVisible = false;
- My code works correctly on the root  level.
- On the other levels it does not work.
- If I start off with one column visible on each level then everything works
- After setting one column visible on each level and then changing it to not visible (the original state I wanted) then subsequent changes to visibility work.  It seem like the grid code expects a least one column to be visible.

For the time being I will make the primary key for each level visible.

Also, since the levels have to be expanded in order for this to work can you show me how to expand all levels programmatically. I used the expand all hierarchy property but that only expanded the first level after the root level.

Thanks
Rich
0
Maya
Telerik team
answered on 11 Apr 2011, 01:25 PM
Hi Richard Harrigan,

I have try to reproduce the issue you reported, but still without any success. May you take a look at the sample attached to verify whether there are any misunderstandings according to your requirements ? 
Furthermore, the sample illustrates how you may expand the hierarchy items on all levels.
 

Greetings,
Maya
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
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Richard Harrigan
Top achievements
Rank 1
Share this question
or