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

[Solved] SelectAll checkbox in gridview Header

6 Answers 341 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.
anoop c
Top achievements
Rank 1
anoop c asked on 14 Dec 2009, 06:47 AM
Hi All,

Has anyone implemented the SelectAll checkbox feature in gridview. I am having difficulty in binding the datacontext to the checkbox placed in Header Template. 
<telerikGridview:GridViewColumns >
<telerikGridview:GridViewColumn width="25">
<telerikGridview:GridViewColumn.Header>
<CheckBox IsChecked="{Binding SelectAll}" />
</telerikGridview:GridViewColumn.Header>
</telerikGridview:GridViewColumn >
....
</telerikGridview:GridViewColumns >


I have read in one article that DataContext binding is not supported for datacolumn header, is it true?

Thanks
Anoop

6 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 14 Dec 2009, 07:12 AM
Hi anoop c,

 Why not use GridViewSelectColumn instead? You can check the first column in this demo:
http://demos.telerik.com/silverlight/#GridView/ColumnTypes


Sincerely yours,
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
anoop c
Top achievements
Rank 1
answered on 14 Dec 2009, 08:17 AM
Vlad,

  Thanks a lot for pointing out this. I was doing a whole circle around the solution but not looking in :-).

But how to get the list of items selected. I am binding a custom class as itemsource of the grid. How do I bind the selected property to get the selected items?  Since I am using the prism/mvvm model I am binding the viewmodel and not using the codebehind.
0
Vlad
Telerik team
answered on 16 Dec 2009, 07:42 AM
Hi anoop c,

 Please check this demo for more info: http://demos.telerik.com/silverlight/#GridView/Selection


Greetings,
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
anoop c
Top achievements
Rank 1
answered on 16 Dec 2009, 09:17 AM
Thanks vlad for help. But I think I need to explain my problem a bit more detail.

 When you use the GridViewSelectColumn then the whole select process is done for you automatically. Now if we need to identify the items which were selected there is a protected property called SelectedItems.  I need to bind a property in my viewmodel to this property in the xaml but since it is not public it is not visible in the xaml.  I could refer to it in the codebehind but I don't want to do that due to the puritan approach towards MVVM and testable ui and hence to have no code codebehind.

Hope the problem is clear.

Thanks
Anoop
0
Accepted
Stefan Dobrev
Telerik team
answered on 22 Dec 2009, 07:44 AM
Hi anoop c,

The SelectedItems property is indeed public. The problem is that it is not a dependency property and cannot be bound. This exactly mimics Microsoft controls behavior, specifically the base Selector class.

If you want a pure XAML solution my suggestion is to use some kind of attached behavior which will synchronize the selected items from the grid to the ones in your model and vice versa.

Hope this help,
Stefan Dobrev
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
anoop c
Top achievements
Rank 1
answered on 22 Dec 2009, 09:15 AM
Thanks Stefan, VLad

 I had addressed the problem exactly as you mentioned. It is working fine.   
 But I would have loved to get the simple approach of binding it directly. Hope in SL4 it would change.



Thanks
Anoop
Tags
GridView
Asked by
anoop c
Top achievements
Rank 1
Answers by
Vlad
Telerik team
anoop c
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or