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

How to walk down Groups to change item-property (like TreeView with Checkboxes)

6 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steffen
Top achievements
Rank 1
Veteran
Steffen asked on 16 Oct 2009, 01:50 PM
Hi,
I have bound the GridView to an collection of business-objects that have a IsSelected-Property(bool) and an according CheckBox-Column.
To be able to change this property for all objects in a group I came up with this:
 
<Style x:Key="CustomRowStyle"  TargetType="telerik:GridViewGroupRow"
    <EventSetter Event="Loaded" Handler="GridViewGroupRow_Loaded" /> 
</Style> 
 
        private void GridViewGroupRow_Loaded(object sender, RoutedEventArgs args) 
        { 
            GridViewGroupRow groupRow = (GridViewGroupRow)args.OriginalSource; 
 
            CheckBox cb = new CheckBox() { Content = groupRow.Group.Key }; 
 
            cb.Tag = groupRow
 
            cb.Checked += new RoutedEventHandler(groupRow_CheckChanged); 
            cb.Unchecked += new RoutedEventHandler(groupRow_CheckChanged); 
 
            groupRow.Header = cb
        } 
 
 
 
        void groupRow_CheckChanged(object sender, RoutedEventArgs e) 
        { 
            GridViewGroupRow groupRow = (sender as CheckBox).Tag as GridViewGroupRow; 
 
            recursiveGroupSelection(groupRow.Group, (sender as CheckBox).IsChecked ?? false); 
        } 
 
        private void recursiveGroupSelection(IGroup g, bool check) 
        { 
            foreach (var item in g.Items)//select items in this group 
            { 
                if (item is BusinessObject) 
                { 
                    (item as BusinessObject).IsSelected = check
                } 
            } 
             
            //the same for all subgroups 
            foreach (Group sub in g.Subgroups) 
            { 
                recursiveGroupStationSelection(sub, check); 
            } 
        } 
1. This checks and unchecks all items in the group and subgroups but I do not know how to get to the GridViewGroupRow of the subgroups and also (un)check their CheckBoxes. I can get the Group from GridViewGroupRow but when walking down the subgroups I do not know how to get their GridViewGroupRows.
2. I also wasn't able to get the PropertyName from the Group - the Group's Key-Property is the actual property's value. How to get the property's name to know what property is grouped by this Group?
3. And it would be very nice if (un)checking items would be reflected in the parent-group-checkbox(es).

Any suggestion is welcome.

Best Regards
Steffen

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 22 Oct 2009, 08:55 AM

Hi Steffen,

Please excuse me for the delayed answer . I am preparing a working sample  for you right now  and will send it as soon as it is functional.

Meanwhile please specify which version of RadGridView are you using , so I can test the sample with the right dlls.

Best wishes,

Pavel Pavlov
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
Steffen
Top achievements
Rank 1
Veteran
answered on 22 Oct 2009, 10:26 AM
Thank you for the support!

I'm currently building with 2009.3.916.35.
0
Pavel Pavlov
Telerik team
answered on 22 Oct 2009, 01:42 PM

Hi Steffen,

Thanks for your patience!  Please find the sample attached. I have tried to resemble your scenario as close as possible . Let me know if any questions appear.  It is kind of raw code but still it demonstrates a way to traverse up and down the groupings tree and set the "IsChecked" state.

Kind regards,

Pavel Pavlov
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
Steffen
Top achievements
Rank 1
Veteran
answered on 22 Oct 2009, 03:16 PM
Hi Pavel,

thank you!
Thats seems to be exactly what I was trying to do. There are still some little issues where groups are skipped but I'm going to try it first thing tomorrow.

Best Regards
Steffen
0
Steffen
Top achievements
Rank 1
Veteran
answered on 23 Oct 2009, 10:42 AM
Hi,
here is the modified sample. Looks like everything works now (regrouping, reordering, no group skipping).
The thing is that it works with 2009.3.916.35 and for some reason not with the dll's in your solution.
With your dll's the custom group-headers are not showing up. Maybe you could check that out so I know that my solution
will work with the upcoming releases.

Best Regards
Steffen

(I didn't manage to upload the zipped-project, look here: www.chaincom.de/fileadmin/154444_selectablegroups-wpf-complete.zip)

(marking your post as answer is currently not working?)
0
Pavel Pavlov
Telerik team
answered on 27 Oct 2009, 02:54 PM
Hello Steffen,


Thanks for reporting this ! We have noticed the problem and we are already woking towards fixing it . I may assure you that the bug will not be present in the upcoming oficial release.
One more time thanks for your collaboration and feedback ! I have updated your Telerik points.

Regards,
Pavel Pavlov
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.
Tags
GridView
Asked by
Steffen
Top achievements
Rank 1
Veteran
Answers by
Pavel Pavlov
Telerik team
Steffen
Top achievements
Rank 1
Veteran
Share this question
or