This is a migrated thread and some comments may be shown as answers.
Clarification on GroupDescriptions.CollectionChanged event
2 Answers 54 Views
This is a migrated thread and some comments may be shown as answers.
Antonis
Top achievements
Rank 2
Antonis asked on 08 Apr 2009, 09:42 AM
Hi, 

I am trying to manipulate the way the user interacts with the RadGridView control.

So, on initialization i add the following event to the grid. 


this.grid.GroupDescriptions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GroupDescriptions_CollectionChanged); 

where GroupDescriptions_CollectionChanged is: 

private void GroupDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
    RadGroupDescription group = null
 
    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
    { 
        group = e.NewItems[0] as RadGroupDescription; 
        grid.Columns[group.PropertyName].IsVisible = false
    } 
    else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) 
    { 
        group = e.OldItems[0] as RadGroupDescription; 
        grid.Columns[group.PropertyName].IsVisible = true
    } 

So, when someone, adds a column to the group panel, i hide that column and vise versa.

Say that i have two columns predefined on my grid as Grouped. I bind my data from a WCF service and everything works fine. When i remove a column, everything still works ok and the column now appears on the column headers since its removed froum the group panel. When i try to add it again, and from that point onwards, the e.Action property (for that column) will always have a value of Reset, so i don't know (in my code) if a column is being added or removed. 

Does Reset means something?? Is there any workarounds on this?!?


Many thanks,

Antonis

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Apr 2009, 01:34 PM
Hello Antonis,

Here is an example how to achieve the same using a bit different approach:
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Telerik.Windows; 
using Telerik.Windows.Controls.GridView; 
 
namespace SaveLoadSettingsWithRadGridViewForSilverlight 
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
 
            RadGridView1.AddHandler(GridViewGroupPanel.GroupingRequestedEvent, new EventHandler<GroupingRequestedEventArgs>(GroupingRequested)); 
                        
            RadGridView1.ItemsSource = new MyBusinessObjects().GetData(100); 
        } 
 
        void GroupingRequested(object sender, GroupingRequestedEventArgs e) 
        { 
            if (e.Action == Telerik.Windows.Controls.GroupingEventAction.Place) 
            {  
                RadGridView1.Columns[e.DataMemberPath].IsVisible = false
            } 
            else if (e.Action == Telerik.Windows.Controls.GroupingEventAction.Remove) 
            { 
                RadGridView1.Columns[e.DataMemberPath].IsVisible = true
            } 
        } 
    } 

There is a small problem however  - the event is not raised properly when you click close (x) button in the group panel item. This will be fixed immediately!

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Antonis
Top achievements
Rank 2
answered on 08 Apr 2009, 02:34 PM
Great, it worked!

Many thanks!
Asked by
Antonis
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Antonis
Top achievements
Rank 2
Share this question
or