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
You can use Grouping event to achieve this. Here is an example:
XAML
<
UserControl
x:Class
=
"SilverlightApplication1.MainPage"
xmlns:d
=
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
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.
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
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.
Thanks
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.
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.
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?)
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.
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 >>
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
;
}
}
}
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.
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 >>
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
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
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.
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
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