Hide grouped column

18 posts, 1 answers
  1. Gilbert van Veen
    Gilbert van Veen avatar
    68 posts
    Member since:
    Oct 2009

    Posted 26 Jan 2010 Link to this post

    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.
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Jan 2010 Link to this post

    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.
  3. DevCraft banner
  4. Gilbert van Veen
    Gilbert van Veen avatar
    68 posts
    Member since:
    Oct 2009

    Posted 26 Jan 2010 Link to this post

    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
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 28 Jan 2010 Link to this post

    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.
  6. Brett Parkhurst
    Brett Parkhurst avatar
    5 posts
    Member since:
    Nov 2009

    Posted 16 Mar 2010 Link to this post

    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
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Mar 2010 Link to this post

    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.
  8. Brett Parkhurst
    Brett Parkhurst avatar
    5 posts
    Member since:
    Nov 2009

    Posted 17 Mar 2010 Link to this post

    I need it in C#.
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Mar 2010 Link to this post

    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.
  10. Brett Parkhurst
    Brett Parkhurst avatar
    5 posts
    Member since:
    Nov 2009

    Posted 17 Mar 2010 Link to this post

    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?) 
  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Mar 2010 Link to this post

    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.
  12. ONUR
    ONUR avatar
    5 posts
    Member since:
    Oct 2011

    Posted 12 Oct 2011 Link to this post

    i have a problem;
    e.GroupDescriptor.Member (Member not available)
    please help...thanks...


  13. ONUR
    ONUR avatar
    5 posts
    Member since:
    Oct 2011

    Posted 14 Oct 2011 Link to this post

    please help
  14. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Oct 2011 Link to this post

    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 >>

  15. ONUR
    ONUR avatar
    5 posts
    Member since:
    Oct 2011

    Posted 18 Oct 2011 Link to this post

    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;
                    }
                }
    }
  16. Arun kumar
    Arun kumar avatar
    2 posts
    Member since:
    Dec 2011

    Posted 20 Mar 2012 Link to this post

    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 :-)
  17. David
    David avatar
    18 posts
    Member since:
    Jan 2011

    Posted 01 Jul 2012 Link to this post

    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.
  18. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Jul 2012 Link to this post

    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 >>

  19. David
    David avatar
    18 posts
    Member since:
    Jan 2011

    Posted 02 Jul 2012 Link to this post

    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
Back to Top
DevCraft banner