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

Hide grouped column

24 Answers 402 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.
Gilbert van Veen
Top achievements
Rank 1
Gilbert van Veen asked on 26 Jan 2010, 10:22 AM
Hi,

I have a grouppanel above my grid. When the user drags a column into this panel the grid is grouped. But is is possible to hide the grouped by column automatically?

In other words If I group by column "City" then the City column should not be shown in the grid it self. When the user removes the City column from the group by panel then the column should be shown in the grid again.

24 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 26 Jan 2010, 10:35 AM
Hi,

You can use Grouping event to achieve this. Here is an example:

XAML
<UserControl x:Class="SilverlightApplication1.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
    <Grid x:Name="LayoutRoot">
        <telerik:RadGridView Grouping="RadGridView_Grouping" ItemsSource="{Binding}" />
    </Grid>
</UserControl>


C#
using System.Linq;
using System.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using System;
 
namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            DataContext = from i in Enumerable.Range(0, 10)
                                       select new MyObject() { ID = i, Name = String.Format("Name{0}", i) };
        }
 
        private void RadGridView_Grouping(object sender, GridViewGroupingEventArgs e)
        {
            var grid = (RadGridView)sender;
            var column = grid.Columns.OfType<GridViewColumn>().Where(c => c.UniqueName == e.GroupDescriptor.Member).FirstOrDefault();
            if (e.Action == CollectionChangeAction.Add)
            {
                if(column != null)
                {
                    column.IsVisible = false;
                }
            }
            else if (e.Action == CollectionChangeAction.Remove)
            {
                if(column != null)
                {
                    column.IsVisible = true;
                }
            }
        }
    }
 
    public class MyObject
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}


Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Gilbert van Veen
Top achievements
Rank 1
answered on 26 Jan 2010, 10:54 AM
Hi Vlad,

Thanks for your suggestion. I thought about the same solution.

Maybe this is something to modify in the next release? Make a property on a column like "HiddenWhenGroupedBy".

Thanks again,

Gilbert
0
Milan
Telerik team
answered on 28 Jan 2010, 08:20 AM

Hi Gilbert van Veen,

Thank you for your excellent feedback! We will be adding such support for RadGridView. We have scheduled this feature to be released with our next major release Q1 2010. I have created a PITS issue which can be used to track the status of this feature.

I have updated your Telerik points.


Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Brett Parkhurst
Top achievements
Rank 1
answered on 16 Mar 2010, 07:18 PM
I am not understanding how to get the current column from the group descriptor in c#.  Can you please provide a code snippet on how to do this same thing in C#?

Thanks
0
Vlad
Telerik team
answered on 17 Mar 2010, 07:30 AM
Hi Brett,

Please check the code in my reply. Here is a snippet:

var column = grid.Columns.OfType<GridViewColumn>().Where(c => c.UniqueName == e.GroupDescriptor.Member).FirstOrDefault();

Kind regards,
Vlad
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
Brett Parkhurst
Top achievements
Rank 1
answered on 17 Mar 2010, 02:24 PM
I need it in C#.
0
Vlad
Telerik team
answered on 17 Mar 2010, 03:29 PM
Hi,

Posted code is actually C#.

Sincerely yours,
Vlad
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
Brett Parkhurst
Top achievements
Rank 1
answered on 17 Mar 2010, 03:43 PM
Ok sorry about that...I was mistaken.  Now I am getting the following error:

Error 1 'Telerik.Windows.Controls.GridViewColumnCollection' does not contain a definition for 'OfType' and no extension method 'OfType' accepting a first argument of type 'Telerik.Windows.Controls.GridViewColumnCollection' could be found (are you missing a using directive or an assembly reference?) 
0
Vlad
Telerik team
answered on 17 Mar 2010, 03:50 PM
Hi Brett,

You need to add:

using System.Linq;

Regards,
Vlad
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
ONUR
Top achievements
Rank 1
answered on 12 Oct 2011, 10:20 AM
i have a problem;
e.GroupDescriptor.Member (Member not available)
please help...thanks...


0
ONUR
Top achievements
Rank 1
answered on 14 Oct 2011, 09:49 AM
please help
0
Maya
Telerik team
answered on 17 Oct 2011, 06:43 AM
Hi Onur,

If you want to get the Member of the group descriptor, you need to cast it first to the appropriate type - in this case GroupDescriptor:

private void clubsGrid_Grouping(object sender, Telerik.Windows.Controls.GridViewGroupingEventArgs e)
        {
            var member = (e.GroupDescriptor as GroupDescriptor).Member;
        }

I would recommend you to run through our online documentation for a reference on grouping, group and column descriptors.
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
ONUR
Top achievements
Rank 1
answered on 18 Oct 2011, 10:35 AM
Hello,
I changed and it worked as follows...Thanks...



public void RadGridView_Grouping(object sender, GridViewGroupingEventArgs e)
        {
            var header = (e.GroupDescriptor as Telerik.Windows.Controls.GridView.ColumnGroupDescriptor).Column.Header;
            var grid = (RadGridView)sender;
            var column = grid.Columns.OfType<GridViewColumn>().Where(c => c.Header == header).FirstOrDefault();
            if (e.Action == GroupingEventAction.Place)
            {
                if (column != null)
                {
                    column.IsVisible = false;
                }
            }
            else if (e.Action == GroupingEventAction.Remove)
            {
                if (column != null)
                {
                    column.IsVisible = true;
                }
            }
}
0
Arun kumar
Top achievements
Rank 1
answered on 20 Mar 2012, 05:54 AM
hi is there a way to hide the colum header when it is grouped under a column group. any one know it pls response ASAP :-)
0
David
Top achievements
Rank 1
answered on 02 Jul 2012, 12:25 AM

Quote:  Hi Gilbert van Veen,

Thank you for your excellent feedback! We will be adding such support for RadGridView. We have scheduled this feature to be released with our next major release Q1 2010. I have created a PITS issue which can be used to track the status of this feature.

I have updated your Telerik points.


Sincerely yours,
Milan 
the Telerik team 


Hello - reply was 2 years ago - was this implemented as a property? It is standard on other grids like the Janus grid and I don't want to add a lot of code to my forms.
0
Vlad
Telerik team
answered on 02 Jul 2012, 05:33 AM
Hello,

 Indeed you can find such property (ShowColumnWhenGrouped) in our latest official version (Q2 2012). 

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
David
Top achievements
Rank 1
answered on 03 Jul 2012, 12:51 AM
Hi Vlad,

I upgraded to Q2 (Version:  2012.2.607.40) and now I have this at Column level.

Unfortunately it does not quite function as I was expecting.

Thanks
0
Michael
Top achievements
Rank 1
answered on 28 Sep 2017, 08:02 PM
I'm using version 2017.2.503.45 of GridView and I can't find a property called 'ShowColumnWhenGrouped'.  What am I doing wrong?
0
Michael
Top achievements
Rank 1
answered on 28 Sep 2017, 08:03 PM
Sorry.  I'm in WPF.  Does RadGridView have this property in WPF?
0
Michael
Top achievements
Rank 1
answered on 28 Sep 2017, 08:04 PM
Sorry.  I'm using WPF.  Does RadGridView have this property in WPF?
0
Vladimir Stoyanov
Telerik team
answered on 02 Oct 2017, 03:58 PM
Hello Gilbert,

You can find the property ShowColumnWhenGrouped on the the columns in RadGridView but not on the RadGridView itself. Here are all the Columns available.

I hope you find this helpful. Let me know if I can be of any further assistance.

Regards,
Vladimir Stoyanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 02 Oct 2017, 05:53 PM

Hi Vladimir,

I'm setting all of the columns to false but they still show when it is grouped. 

GridViewFamilies.ItemsSource = FamilyInfoViewModel.FamilyInfoCollection;
foreach (GridViewColumn col in GridViewFamilies.Columns)
       col.ShowColumnWhenGrouped = false;

What am I doing wrong? Thanks.

0
Vladimir Stoyanov
Telerik team
answered on 03 Oct 2017, 11:17 AM
Hi Gilbert,

Since the ShowColumnWhenGrouped property works as intended on my end, may I kindly ask you to prepare a sample project where you are showing the behavior you are describing.

I look forward to hearing from you.

Regards,
Vladimir Stoyanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 03 Oct 2017, 08:40 PM

Vladimir,

I got it to work by moving the code into the Window_Loaded event.  I had it in the window constructor and for some reason it was running before the gridview was populated with the data.  Thanks.

Michael

Tags
GridView
Asked by
Gilbert van Veen
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Gilbert van Veen
Top achievements
Rank 1
Milan
Telerik team
Brett Parkhurst
Top achievements
Rank 1
ONUR
Top achievements
Rank 1
Maya
Telerik team
Arun kumar
Top achievements
Rank 1
David
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or