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

WPF RadGridView header row double click

7 Answers 458 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 11 Oct 2016, 01:04 PM

Hello everyone

I got a radgridView  with an autogeneratingColumn to false

<telerik:RadGridView Margin="8,10,8,32.96" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserResizeRows="False"
                        CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="False" RowIndicatorVisibility="Visible" ItemsSource="{Binding Files}" SelectedItem="{Binding SelectedFile}"
                        AutoGeneratingColumn="GridViewDataControlOnAutoGeneratingColumn" IsFilteringAllowed="True" PreparingCellForEdit="GridViewDataControl_OnPreparingCellForEdit" />

This radGidview show some line with some column Checkbox (not fix column count, depend on data), see attached file. My goal is when user double click header row, all row checkbox will be checked, and the best of the best would be I could put a row checkbox in the header row but I don't think it's possible.

I also tried to put some command line like a button column but I can't get the right selected row when button is first clicked.

See below for the autogenerating column event :

Private Sub GridViewDataControlOnAutoGeneratingColumn(sender As Object, e As GridViewAutoGeneratingColumnEventArgs)
    Dim dataColumn = TryCast(e.Column, GridViewDataColumn)
 
    If (dataColumn Is Nothing) Then Return
 
    If (e.Column.UniqueName = "FileName") Then
      e.Column.Header = "File Name"
      e.Column.DisplayIndex = 0
      e.Column.Width = 200
    ElseIf (e.Column.UniqueName = "AssignedTag") Then
      Dim column = New GridViewComboBoxColumn()
      column.DataMemberBinding = CType(e.Column, GridViewDataColumn).DataMemberBinding
      column.ItemsSource = CType(Me.DataContext, FileViewModel).AcceptedTags
      column.Header = "Assigned Tag"
      column.DisplayIndex = 1
      column.Width = 200
      column.IsFilterable = False
      e.Column = column
    Else
      Dim checkBoxColumn = New GridViewCheckBoxColumn()
      checkBoxColumn.DataMemberBinding = dataColumn.DataMemberBinding
      checkBoxColumn.Header = dataColumn.Header
      checkBoxColumn.UniqueName = dataColumn.UniqueName
      checkBoxColumn.EditTriggers = GridViewEditTriggers.CellClick
      checkBoxColumn.AutoSelectOnEdit = True
      checkBoxColumn.Width = 50
      checkBoxColumn.HeaderTextAlignment = TextAlignment.Center
      checkBoxColumn.TextAlignment = TextAlignment.Center
      Dim sty As New Style(GetType(GridViewCell))
      sty.Setters.Add(New Setter With {.Property = GridViewCell.HorizontalContentAlignmentProperty, .Value = HorizontalAlignment.Center})
      checkBoxColumn.CellStyle = sty
 
      e.Column = checkBoxColumn
    End If
 
    Dim binding = New Binding("IsInEditMode")
    binding.Converter = Me._invertedBooleanConverter
 
    e.Column.SetBinding(Telerik.Windows.Controls.GridViewColumn.IsReadOnlyProperty, binding)
  End Sub

So how Can I got a double click on header row or insert a checkbox into header row ?

thansk

Regards

7 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 14 Oct 2016, 12:06 PM
Hi,

Column's Header is an object and you can define a checkbox in it:
<telerik:GridViewCheckBoxColumn>
                   <telerik:GridViewCheckBoxColumn.Header>
                       <CheckBox/>
                   </telerik:GridViewCheckBoxColumn.Header>
               </telerik:GridViewCheckBoxColumn>

I would suggest you check this forum thread where a similar question is already discussed.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
JC
Top achievements
Rank 1
answered on 14 Oct 2016, 01:41 PM

Hi Yan

Thanks for your answer but I know GridviewCheckBoxColumnHeader and it's not my goal.

My goal is to put a checkbox into a ROW header or add a double click event on RowHeader in order to check all checkbox of a row not a column.

Thanks

0
Yoan
Telerik team
answered on 19 Oct 2016, 12:34 PM
Hello,

May I ask you to specify what do you mean by "header row"? If you are referring to the GridViewIndentCell of GridViewRow element, I would suggest predefine the template of the GridViewRow and define a checkbox  in the "PART_IndicatorPresenter" border. Then you can bind its IsChecked property to a property of your object(the one behind GridView's row). In this way, you can control the checked state of the other checkboxes.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
JC
Top achievements
Rank 1
answered on 19 Oct 2016, 01:13 PM

Hello Yoan

I think it's the good way, I'll take a look to your links.

I put a print screen of what I want to do in attached file. I talked about header row because the property I used to make the first cell visible is "RowIndicatorVisibility".

Do you think I could use your explanation with autogeneratingColumn ?

Thanks

Regards

JC

0
Accepted
Yoan
Telerik team
answered on 19 Oct 2016, 01:33 PM
Hello,

Thank you for the clarification. 

The suggested approach will work with autogenerated columns. However, you can try the other approach - by handling GridView's MouseDouble click event. You need to check what is the clicked element and set the needed properties of your business object:
private void clubsGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
       {
           var indicatorBorder = (e.OriginalSource as FrameworkElement).ParentOfType<Border>();
           if (indicatorBorder.Name == "PART_IndicatorPresenter")
           {
               var item = indicatorBorder.ParentOfType<GridViewRow>().Item;
               if (item != null)
               {
                   // iterate over your properties. In this case Club is the business object.
 
                   var club = item as Club;
                   club.IsActive1 = true;
                   club.IsActive2 = true;
    
               }
           }
       }

I hope this helps.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
JC
Top achievements
Rank 1
answered on 20 Oct 2016, 07:55 AM

Hello Yoan

Thanks for your 2 solutions, the second one (MouseDoubleClick) works well.

But I tried the first one, and I think I missed something, below you could find the code I wrote, could you tell me what I missed ?

<UserControl.Resources>
        <ResourceDictionary>
             
...
 
            <Style TargetType="telerik:GridViewHeaderIndentCell">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="telerik:GridViewHeaderIndentCell">
                            <telerik:SelectiveScrollingGrid>
                                <Border x:Name="PART_IndicatorPresenter" Grid.Row="1" Width="25" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0 0 1 1" >
                                        <CheckBox/>
                                    </Border>
                            </telerik:SelectiveScrollingGrid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
 
...
 
        <telerik:RadGridView Margin="8,10,8,32.96" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserResizeRows="False"
                         CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="False" RowIndicatorVisibility="Visible" ItemsSource="{Binding Files}" SelectedItem="{Binding SelectedFile}"
                         AutoGeneratingColumn="GridViewDataControlOnAutoGeneratingColumn" IsFilteringAllowed="True" PreparingCellForEdit="GridViewDataControl_OnPreparingCellForEdit">
 
        </telerik:RadGridView>
...

 

Thanks

regards

0
JC
Top achievements
Rank 1
answered on 21 Oct 2016, 08:52 AM

Hello Yoan,

I finally found what I missed, so if someone need the same thing, I copy my code below.

<UserControl.Resources>
        <ResourceDictionary>
            ...
            <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource {x:Type telerik:GridViewRow}}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="telerik:GridViewRow">
                            <telerik:SelectiveScrollingGrid>
                                <telerik:SelectiveScrollingGrid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </telerik:SelectiveScrollingGrid.ColumnDefinitions>
                                <Border x:Name="PART_GridViewHeaderRowBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="4" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <Border BorderThickness="0" Background="{TemplateBinding Background}"/>
                                </Border>
                                <telerik:DataCellsPresenter x:Name="PART_DataCellsPresenter" Grid.Column="3"/>
                                <Border x:Name="PART_IndicatorPresenter" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,0" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="{TemplateBinding RowIndicatorVisibility}" Width="25">
                                    <Border BorderThickness="1" VerticalAlignment="Center" HorizontalAlignment="Center">
                                        <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" Checked="CheckAll_OnChange" Unchecked="CheckAll_OnChange"/>
                                    </Border>
                                     
                                </Border>
                                <telerik:IndentPresenter x:Name="PART_IndentPresenter" Grid.Column="1"  IndentLevel="{TemplateBinding IndentLevel}" MinHeight="{TemplateBinding MinHeight}" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" telerik:StyleManager.Theme="{StaticResource Theme}"/>
                                <Border x:Name="PART_HierarchyIndentPresenter" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,1,1" Grid.Column="2" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="{Binding HasHierarchy, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" Width="25">
                                    <Border BorderThickness="1" />
                                </Border>
                            </telerik:SelectiveScrollingGrid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
 
...
 
<telerik:RadGridView Margin="8,10,8,32.96" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserResizeRows="False"
                         CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="False" ItemsSource="{Binding Files}" SelectedItem="{Binding SelectedFile}"
                         AutoGeneratingColumn="GridViewDataControlOnAutoGeneratingColumn" RowIndicatorVisibility="Visible" IsFilteringAllowed="True" PreparingCellForEdit="GridViewDataControl_OnPreparingCellForEdit"/>
 
...

 

Private Sub CheckAll_OnChange(sender As Object, e As RoutedEventArgs)
    Dim model As FileViewModel = CType(Me.DataContext, FileViewModel)
    'TODO
    'model.Action
  End Sub

 

thanks

Regards

Tags
GridView
Asked by
JC
Top achievements
Rank 1
Answers by
Yoan
Telerik team
JC
Top achievements
Rank 1
Share this question
or