<telerik:RadGridView x:Name="WiresGV" AutoGenerateColumns="False" Grid.Row="1" ItemsSource="{Binding Wires}" ShowGroupPanel="False" ShowInsertRow="True" AlternateRowBackground="OliveDrab" clr:XWireAppCommands.DataGridDoubleClickCommand="{Binding TarunCommand}"> <telerik:RadGridView.Columns> <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected}" Name="CBCol" AutoSelectOnEdit="True" IsFilterable="False" Width="60"> <telerik:GridViewCheckBoxColumn.Header> <CheckBox Content="Select" Name="HeaderItem" Click="Button6_Click" Foreground="White"></CheckBox> </telerik:GridViewCheckBoxColumn.Header> </telerik:GridViewCheckBoxColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding WireDate}" Header="Date" DataFormatString=" {0:dd, MMM, yyyy}" />.....For Each row As GridViewRow In Me.WiresGV.ChildrenOfType(Of GridView.GridViewRow)() If (TypeOf row Is GridViewNewRow) Then Continue For End If Dim cb As CheckBox cb = row.Cells(0).ChildrenOfType(Of CheckBox)().FirstOrDefault
cb.IsChecked = True
Next11 Answers, 1 is accepted
You may use the built-in GridViewSelectColumn which provides this functionality out-of-the-box. Since you have set the SelectionMode property either to Multiple or Extended you will be able to use the CheckBox control within the Header and the ability to select all items in RadGridView.
Vanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
GridViewSelectColumnis internally bound to the GridViewRow'sIsSelected property. By that reason it cannot be related to another custom property of your ViewModel.
You may define the GridViewCheckBoxColumn's Header, bind it to the property you want and predefine its Header in an appropriate manner, refer to the following:
<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsPlaying}"> <telerik:GridViewCheckBoxColumn.Header> <CheckBox telerik:StyleManager.Theme="Office_Black" Click="CheckBox_Click" /> </telerik:GridViewCheckBoxColumn.Header></telerik:GridViewCheckBoxColumn>Private Sub CheckBox_Click(sender As Object, e As System.Windows.RoutedEventArgs) Dim checkBox = TryCast(sender, CheckBox) If checkBox IsNot Nothing Then If checkBox.IsChecked.GetValueOrDefault() Then Me.playersGrid.SelectAll() Else Me.playersGrid.UnselectAll() End If End IfEnd SubVanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
From my understanding
Me.playersGrid.SelectAll() will select all rows in the datagrid. Instead , i want to check the checkbox column. Pls advise
The solution below demonstrates how to implement the GridViewSelectColumn using standard GridViewCheckBoxColumn. As I can understand you want to select the cells in that particular column when you click on the header. Keep in mind that you may select rows when the SelectionMode is set to FullRow and to select cells when the SelectionMode property of RadGridView is set to Cell. You may use extension method ChildrenOfType and to find the cells in a particular column and set its IsSelected property to True.
Vanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
I am trying the following code but cb is always nothing. Can you advise why that is happening. I am not able to find documentation for row.cells ...
For Each row As GridViewRow In Me.WiresGV.ChildrenOfType(Of GridView.GridViewRow)() If (TypeOf row Is GridViewNewRow) Then Continue For End If Dim cb As CheckBox cb = row.Cells(0).ChildrenOfType(Of CheckBox)().FirstOrDefault
cb.IsChecked = True
Next
You should use the following as a pattern:
<telerik:RadGridView x:Name="gridView" ItemsSource="{Binding Collection}" SelectionUnit="Cell" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewCheckBoxColumn Width="100" DataMemberBinding="{Binding Property2}"> <telerik:GridViewCheckBoxColumn.Header> <CheckBox telerik:StyleManager.Theme="Office_Black" Checked="CheckBox_Checked"/> </telerik:GridViewCheckBoxColumn.Header> </telerik:GridViewCheckBoxColumn> </telerik:RadGridView.Columns> </telerik:RadGridView> Private Sub CheckBox_Checked(sender As Object, e As RoutedEventArgs) Dim checkBox = DirectCast(sender, CheckBox) If checkBox IsNot Nothing Then If checkBox.IsChecked = True Then Dim grid = checkBox.ParentOfType(Of RadGridView)() Dim cells = grid.ChildrenOfType(Of GridViewCell)().Where(Function(f) f.Column.DisplayIndex = 0).ToList() For Each cell As var In cells cell.IsSelected = True Next End If End IfEnd SubYou may change this snippet in the way you need. You may read more about Selection in RadGridView in our online docs, please follow this link.
Regards,
Vanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
The best approach here would be not to iterate the UI elements. It is better to iterate trough your business objects and set their "IsSelected" property to true .
Since checkboxes are bound to this property, the will automatically update to the proper state.
In other words instead of finding the checkboxes, just make a "foreach" in the items used as ItemsSource for the gird and set their property.
* in order this to have effect ,your objects need to implement the INotifyPropertyChanged Interface. This will allow RadGridView to sense the change and update the UI with the new checked states "
If all this sounds obscure, just paste me the implementation of your business object and I will gather a small sample for you .
Greetings,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
We can debug this for you but we will need a runnable repro to step through it and see what and where went wrong.
Having only fragments of the code , I can just guess what may be the cause for the trouble.
All the best,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>