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

Hosting Control in Column Header

3 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gregory Donovan
Top achievements
Rank 1
Gregory Donovan asked on 29 Jun 2010, 05:47 PM
I need a checkbox column that has a checkbox control in the header that will mimic what the GridViewSelectColum does.  I cannot use the GridViewSelectColumn because I'm not looking to select all rows - I just want to check all rows - like mark all as read functionality.  To achieve this I simply put a CheckBox control in the header of my bool column and set the binding to a property in my VM called CheckAll.

<CheckBox IsChecked="{Binding CheckAll, diagnostics:PresentationTraceSources.TraceLevel=High}"></CheckBox>

The setter on my property is not being called and when I added the diagnostics the binding does not show up.  However, when I move the checkbox outside of the grid it works fine - so I'm thinking the reference is lost?

Thanks,

Greg


3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Jul 2010, 09:09 AM
Hi Gregory Donovan,

 
Indeed most probably the result of the unexpected behavior is because of the Binding being set in the definition of the CheckBox and the fact that the Property "CheckAll" may not be visible in the place of the visual tree. So, in order to be more helpful, we would need more details about the way you are exposing your ItemsSource/ DataContext for the grid and how exactly you are defining the ComboBox.
 

Sincerely yours,
Maya
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
0
Gregory Donovan
Top achievements
Rank 1
answered on 06 Jul 2010, 05:20 PM
Hi Maya,

The DataContext is set to a class (ViewModel) with a property named Items in the form of ObservableCollection<ViewModelItem> - the RadGridView's ItemSource property is set to this property.  This class has another property called CheckAll which I've bound to a CheckBox that is in the header of a column (bound to IsChecked property).  The idea is that when this is checked I will have code in the 'setter' to then go through and update a property in all of the items in the collection.

XAML of grid with first column with CheckBox in header is below.

<div><div>&nbsp;&nbsp; &lt;telerikGrid:RadGridView Name="Grid" Grid.Row="0"&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ItemsSource="{Binding Items}"&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HorizontalContentAlignment="Stretch"&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SelectionMode="Single"&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AutoGenerateColumns="False"&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SelectedItem="{Binding SelectedItem}" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScrollMode="Deferred"</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EnableRowVirtualization="True"&gt;</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;telerikGrid:RadGridView.Columns&gt;</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;telerikGrid:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected}" IsFilterable="False" AutoSelectOnEdit="True"&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;telerikGrid:GridViewColumn.Header&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;!--&lt;CheckBox Click="CheckAll_Click"&gt;&lt;/CheckBox&gt;--&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;CheckBox IsChecked="{Binding CheckAll}"&gt;&lt;/CheckBox&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/telerikGrid:GridViewColumn.Header&gt;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/telerikGrid:GridViewCheckBoxColumn&gt;</div></div><div><div></div></div

Let me know if you need more information.

Greg
0
Pavel Pavlov
Telerik team
answered on 07 Jul 2010, 09:09 AM
Hi Gregory Donovan,

To be able to bind to your ViiewModel  you will need to expose it as a static resource , the you should use syntax like :

<CheckBox IsChecked="{Binding CheckAll,Source = {StaticResource MyViewModel} ....

where MyViewModel is the key of the static resource.

Let me know in case you need a small sample app on that.

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