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

How to change behavior of the Enter Key in RadGridView

14 Answers 1355 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 13 Feb 2013, 08:00 PM

I have a WPF application which contains a window, which has a RadGridView control in it.  There's an action that I want to occur when the user double clicks on a row in the `RadGridView` control, or if they press the `Enter` key while a row is selected.

The `RadGridView` control currently has an event handler associated with the `MouseDoubleClick` event.  What I want to do is to execute the same code that's in the `MouseDoubleClick` event handler when the user presses the `Enter` key and a row is selected in the `RadGridView`.  I've already moved that code into a helper method that can be called from either place.

Right now, pressing enter while a row is selected in the RadGridView control causes the row after the currently selected one to be selected.  How do I change the behavior associated with pressing the Enter key?

14 Answers, 1 is accepted

Sort by
0
Tony
Top achievements
Rank 1
answered on 13 Feb 2013, 08:23 PM
I was able to make this work.

What I did was I added CommandBindings to the Window for my custom command:
<Window xmlns:cs=". . ."
        . . .>
    <Window.CommandBindings>
        <CommandBinding CanExecute="MyCustomAction_CanExecute" Command="cs:MyCustomCommands.MyCustomAction" Execute="MyCustomAction_Execute" />
    </Window.CommandBindings>
 
    . . .
</Window>

Then I added InputBindings to the RadGridView:

<telerik:RadGridView . . .>
    <telerik:RadGridView.InputBindings>
        <KeyBinding Key="Enter" Command="{x:Static cs:MyCustomCommands.MyCustomAction" />
    </telerik:RadGridView.InputBindings>
</telerik:RadGridView

This works perfectly.  My CanExecute method is being called when you press the Enter key.  If a row is selected in the RadGridView, the CanExecute method sets the e.CanExecute property to true and my Execute method gets called.

Thanks anyway.
0
Maya
Telerik team
answered on 14 Feb 2013, 07:25 AM
Hi Tony,

 
I am glad to see that you have a proper solution on your own. Yet another approach would be to work with CustomKeyboardCommandProvider as illustrated in our documentation and blogs.
It is up to you to decide which is more appropriate for your exact scenario. 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 15 Feb 2013, 03:56 PM
Actually, there is a problem with my solution.  Specifically, the form has a Button on it that has IsDefault=true set in the Xaml.  Before I added the InputBindings to the RadGridView, pressing the Enter key anywhere on the form except in the RadGridView control would cause the action for that Button to be performed, but now, it doesn't.  The Enter key does nothing unless the focus is in the RadGridView control.

This is not what I want.   If the focus is on any control except the RadGridView, I want the Button's action to be performed.

Here's the complete XAML of my form:

<UserControl x:Class="CarSystem.CustomControls.Searcher"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:cs="clr-namespace:CarSystem.CustomControls"
             xmlns:vm="clr-namespace:CarSystem.ServiceModel;assembly=ViewModels"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d"
             Height="620"
             IsVisibleChanged="Searcher_IsVisibleChanged"
             Loaded="Searcher_Loaded"
             Width="990">
     
    <UserControl.CommandBindings>      
        <CommandBinding CanExecute="DisplayEditHotListEntry_CanExecute"  Command="cs:CarSystemCommands.DisplayEditHotListEntry"  Executed="DisplayEditHotListEntry_Executed" />
        <CommandBinding CanExecute="DisplayEditRecordDetails_CanExecute" Command="cs:CarSystemCommands.DisplayEditRecordDetails" Executed="DisplayEditRecordDetails_Executed" />
    </UserControl.CommandBindings>
 
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
        <CollectionViewSource         x:Key="ReadsView" />
        <cs:BooleanInverter           x:Key="NotBool" />
        <cs:CoordinateConverter       x:Key="CoordConverter" />
        <cs:DateConverter             x:Key="DateConverter" />
        <cs:EnumToBitmapConverter     x:Key="DeviceStatuses" Type="{x:Type vm:DeviceStatuses}" />
        <cs:GreaterOrEqualConverter   x:Key="GreaterOrEqual" />
        <cs:Int32Converter            x:Key="IntConverter" />
        <cs:MultiBoolConverter        x:Key="CombineBools" />
 
        <cs:AlarmsRowStyleSelector x:Key="StyleSelector">
            <cs:AlarmsRowStyleSelector.IgnoreThis>
                <Style BasedOn="{StaticResource {x:Type telerik:GridViewRow}}" TargetType="telerik:GridViewRow" />
            </cs:AlarmsRowStyleSelector.IgnoreThis>
            <cs:AlarmsRowStyleSelector.IsAlarmStyle>
                <Style BasedOn="{StaticResource {x:Type telerik:GridViewRow}}" TargetType="telerik:GridViewRow">
                    <Setter Property="Foreground" Value="{DynamicResource AlarmTextForeground}" />
                    <Setter Property="Background" Value="{DynamicResource DataBackground}" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="{DynamicResource DataBackgroundSelected}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </cs:AlarmsRowStyleSelector.IsAlarmStyle>
            <cs:AlarmsRowStyleSelector.NotAlarmStyle>
                <Style BasedOn="{StaticResource {x:Type telerik:GridViewRow}}" TargetType="telerik:GridViewRow">
                    <Setter Property="Foreground" Value="{DynamicResource TextForeground}" />
                    <Setter Property="Background" Value="{DynamicResource DataBackground}" />
                </Style>
            </cs:AlarmsRowStyleSelector.NotAlarmStyle>
        </cs:AlarmsRowStyleSelector>
         
        <DataTemplate x:Key="CheckableChoice">
            <CheckBox Content="{Binding Path=Value}"
                      IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" />
        </DataTemplate>
 
        <Storyboard x:Key="FlashTextBlockText">
            <ObjectAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Hidden}" />
                <DiscreteObjectKeyFrame KeyTime="0:0:1"   Value="{x:Static Visibility.Visible}" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
 
        <Style BasedOn="{StaticResource {x:Type TextBlock}}" x:Key="FlashBlockText" TargetType="TextBlock">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsSearching, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="StartFlashingTextBox" Storyboard="{StaticResource FlashTextBlockText}" />
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="StartFlashingTextBox" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
     
    <Grid Background="{DynamicResource ContentBackground}"
          Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="110" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
 
        <Grid Grid.Column="0"
              Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
 
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="0"
                      Grid.Row="0"
                      Header="Plate:"
                      Margin="5,0">
                <Border BorderBrush="{DynamicResource ControlBorder}"
                        BorderThickness="1"
                        Height="35"
                        Margin="5"
                        VerticalAlignment="Top">
                    <TextBox FontSize="16"
                             FontWeight="Bold"
                             GotFocus="PlateBox_GotFocus"
                             LostFocus="PlateBox_LostFocus"
                             MaxLength="25"
                             MaxLines="1"
                             Name="PlateBox"
                             TabIndex="0"
                             TextChanged="PlateBox_TextChanged"
                             ToolTip='Wildcards ("%", "_") can be used' />
                </Border>
            </GroupBox>
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="0"
                      Grid.Row="1"
                      Header="State:"
                      Margin="5,0">
                <cs:TouchComboBox Background="{DynamicResource UnfocusedBackground}"
                                  BorderBrush="{DynamicResource ControlBorder}"
                                  DisplayMemberPath="Value"
                                  FontSize="16"
                                  FontWeight="Bold"
                                  Foreground="{DynamicResource UnfocusedForeground}"
                                  GridBackground="{DynamicResource ContentBackground}"
                                  Height="50"
                                  ItemsSource="{Binding Path=LocaleChoices, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                  Margin="5"
                                  x:Name="StatePicker"
                                  SelectedValuePath="Key"
                                  SelectionChanged="StatePicker_SelectionChanged"
                                  TabIndex="1"
                                  TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                  VerticalAlignment="Center" />
            </GroupBox>
 
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="1"
                      Grid.Row="0"
                      Header="Start Date:"
                      Margin="5,0">
                <telerik:RadDateTimePicker FontSize="16"
                                           FontWeight="Bold"
                                           Height="35"
                                           Margin="5"
                                           Name="StartDatePicker"
                                           SelectionChanged="DateTimePicker_SelectionChanged"
                                           TabIndex="2"
                                           VerticalAlignment="Top" />
            </GroupBox>
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="1"
                      Grid.Row="1"
                      Header="End Date:"
                      Margin="5,0">
                <telerik:RadDateTimePicker FontSize="16"
                                           FontWeight="Bold"
                                           Height="35"
                                           Margin="5"
                                           Name="EndDatePicker"
                                           SelectionChanged="DateTimePicker_SelectionChanged"
                                           TabIndex="3"
                                           VerticalAlignment="Center" />
            </GroupBox>
 
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="2"
                      Grid.Row="0"
                      Header="Alarm Class:"
                      Margin="5,0">
                <Grid VerticalAlignment="Center">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="35" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <CheckBox Click="AllAlarmClasses_Click"
                              Content="ALL"
                              FontSize="16"
                              FontWeight="Bold"
                              Grid.Column="0"
                              Grid.Row="0"
                              HorizontalAlignment="Left"
                              Margin="5"
                              Name="AllAlarmClassesCheckBox"
                              TabIndex="4"
                              VerticalAlignment="Center" />
                    <Button Click="ExpandPicker_Click"
                            Content="Expand"
                            FontSize="16"
                            FontWeight="Bold"
                            Grid.Column="1"
                            Grid.Row="0"
                            Height="30"
                            Name="ExpandAlarmClass"
                            TabIndex="5" />
                    <ListBox BorderBrush="Black"
                             BorderThickness="1"
                             CheckBox.Click="AlarmClassPicker_Click"
                             ItemTemplate="{StaticResource CheckableChoice}"
                             FontSize="16"
                             FontWeight="Bold"
                             Grid.Column="0"
                             Grid.ColumnSpan="2"
                             Grid.Row="1"
                             Height="100"
                             ItemsSource="{Binding Path=AlarmClassChoices, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}, Mode=TwoWay}"
                             Margin="5,0"
                             Name="AlarmClassPicker"
                             SelectionMode="Multiple"
                             TabIndex="6"
                             Visibility="Collapsed" />
                </Grid>
            </GroupBox>
 
            <GroupBox BorderBrush="{DynamicResource ControlBorder}"
                      FontSize="16"
                      FontWeight="Bold"
                      Foreground="{DynamicResource TextForeground}"
                      Grid.Column="2"
                      Grid.Row="1"
                      Header="Hot List:"
                      Margin="5,0">
                <cs:TouchComboBox Background="{DynamicResource UnfocusedBackground}"
                                  BorderBrush="{DynamicResource ControlBorder}"
                                  DisplayMemberPath="Value"
                                  FontSize="16"
                                  FontWeight="Bold"
                                  Foreground="{DynamicResource UnfocusedForeground}"
                                  GridBackground="{DynamicResource ContentBackground}"
                                  Height="50"
                                  IsTabStop="True"
                                  ItemsSource="{Binding Path=HotListChoices, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}, Mode=TwoWay}"
                                  KeyboardNavigation.TabIndex="4"
                                  Margin="5,0,0,0"
                                  x:Name="HotListPicker"
                                  SelectedIndex="0"
                                  SelectedValuePath="Key"
                                  SelectionChanged="SourcePicker_SelectionChanged"
                                  TabIndex="7"
                                  TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                  VerticalAlignment="Center" />
            </GroupBox>        
        </Grid>
 
        <TabControl Background="{DynamicResource TabBackground}"
                    Grid.Row="1"
                    Margin="0,20,0,5"
                    Name="ResultTabs">
 
            <TabItem Background="{DynamicResource TabHeaderBackground}"
                     FontSize="16"
                     FontWeight="Bold"
                     Foreground="{DynamicResource TabHeaderForeground}"
                     Header="Hot List Entries:"
                     Name="HotListEntryTab">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
 
                    <telerik:RadGridView AutoExpandGroups="True"
                                         AutoGenerateColumns="False"
                                         CanUserDeleteRows="False"
                                         CanUserFreezeColumns="False"
                                         CanUserInsertRows="False"
                                         CanUserResizeColumns="True"
                                         CanUserSortColumns="True"
                                         EnableColumnVirtualization="True"
                                         EnableRowVirtualization="True"
                                         FontSize="16"
                                         FontWeight="Bold"
                                         Grid.Row="0"
                                         IsBusy="{Binding Path=IsLoadingHotLists, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                         IsReadOnly="True"
                                         MouseDoubleClick="HotListEntriesGrid_MouseDoubleClick"
                                         Name="HotListEntriesGrid"
                                         RowIndicatorVisibility="Collapsed"
                                         SelectionChanged="HotListEntriesGrid_SelectionChanged"
                                         SelectionUnit="FullRow"
                                         ScrollViewer.CanContentScroll="True"
                                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                                         ShowGroupFooters="True"
                                         ToolTip="Matching Hot List Entries">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Plate,      Mode=OneWay}"
                                                        Header="Plate"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding LocaleCode, Mode=OneWay}"
                                                        Header="State"
                                                        Width="75" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ListName,   Mode=OneWay}"
                                                        Header="Hot List"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding AlarmClass, Mode=OneWay}"
                                                        Header="Alarm Class"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Notes,     Mode=OneWay}"
                                                        Header="Notes"
                                                        Width="*">
                                <telerik:GridViewDataColumn.ToolTipTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Notes, Mode=OneWay}" />
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.ToolTipTemplate>
                            </telerik:GridViewDataColumn>
                        </telerik:RadGridView.Columns>
                        <telerik:RadGridView.InputBindings>
                            <KeyBinding Key="Enter" Command="{x:Static cs:CarSystemCommands.DisplayEditHotListEntry}" />
                        </telerik:RadGridView.InputBindings>
                    </telerik:RadGridView>
                     
                    <cs:PageSelector FontSize="16"
                                     FontWeight="Bold"
                                     Foreground="{DynamicResource TextForeground}"
                                     GetPageData="GetHotListEntryPage"
                                     Grid.Row="1"
                                     IsRetrievingData="{Binding Mode=TwoWay, Path=IsLoadingHotLists, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     Margin="0,5,0,0"
                                     x:Name="HotListEntriesPageSelector"
                                     NumberOfRows="{Binding Mode=TwoWay, Path=NoHotListEntries, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     PageContentsChanged="HotListEntriesPageSelector_PageContentsChanged"
                                     PageSize="{Binding Mode=TwoWay,Path=AdvancedSettings.PageSize, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}" />
                     
                </Grid>
            </TabItem>
 
            <TabItem Background="{DynamicResource TabHeaderBackground}"
                     FontSize="16"
                     FontWeight="Bold"
                     Foreground="{DynamicResource TabHeaderForeground}"
                     Header="Reads & Alarms:"
                     IsSelected="True"
                     Name="ReadsTabItem">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
 
                    <telerik:RadGridView AutoExpandGroups="True"
                                         AutoGenerateColumns="False"
                                         CanUserDeleteRows="False"
                                         CanUserFreezeColumns="False"
                                         CanUserInsertRows="False"
                                         CanUserResizeColumns="True"
                                         CanUserSortColumns="True"
                                         EnableColumnVirtualization="True"
                                         EnableRowVirtualization="True"
                                         FontSize="16"
                                         FontWeight="Bold"
                                         IsBusy="{Binding Path=IsLoadingReads, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                         IsReadOnly="True"
                                         MouseDoubleClick="ReadsGrid_MouseDoubleClick"
                                         Name="ReadsGrid"
                                         RowIndicatorVisibility="Collapsed"
                                         RowStyleSelector="{StaticResource StyleSelector}"
                                         SelectionChanged="ReadsGrid_SelectionChanged"
                                         SelectionUnit="FullRow"
                                         ScrollViewer.CanContentScroll="True"
                                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                                         ShowGroupFooters="True"
                                         ToolTip="Matching Reads">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Plate,     Mode=OneWay}"
                                                        Header="Plate"
                                                        Width="*" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding State,     Mode=OneWay}"
                                                        Header="State"
                                                        Width="75" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding TimeStamp,  Mode=OneWay, Converter={StaticResource DateConverter}}"
                                                        Header="Date & Time"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding GPSInformation.Position.Latitude, Mode=OneWay, Converter={StaticResource CoordConverter}, ConverterParameter=NS}"
                                                        Header="Latitude"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding GPSInformation.Position.Longitude, Mode=OneWay, Converter={StaticResource CoordConverter}, ConverterParameter=EW}"
                                                        Header="Longitude"
                                                        Width="Auto" />
                            <telerik:GridViewImageColumn DataMemberBinding="{Binding GpsQuality, Mode=OneWay, Converter={StaticResource DeviceStatuses}}"
                                                         Header="Gps Quality"
                                                         ImageStretch="None"
                                                         Width="125" />
                        </telerik:RadGridView.Columns>
                        <telerik:RadGridView.InputBindings>
                            <KeyBinding Key="Enter" Command="{x:Static cs:CarSystemCommands.DisplayEditRecordDetails}" />
                        </telerik:RadGridView.InputBindings>
                    </telerik:RadGridView>
 
                    <cs:PageSelector FontSize="16"
                                     FontWeight="Bold"
                                     Foreground="{DynamicResource TextForeground}"
                                     GetPageData="GetReadsPage"
                                     Grid.Row="1"
                                     IsRetrievingData="{Binding Mode=TwoWay, Path=IsLoadingReads, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     Margin="0,5,0,0"
                                     x:Name="ReadsPageSelector"
                                     NumberOfRows="{Binding Mode=TwoWay, Path=NoReads, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     PageContentsChanged="ReadsPageSelector_PageContentsChanged"
                                     PageSize="{Binding Mode=TwoWay,Path=AdvancedSettings.PageSize, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                                     TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}" />
                </Grid>
            </TabItem>
        </TabControl>
 
        <GridSplitter Background="{DynamicResource SeparatorColor}"
                      Grid.Row="1"
                      Height="10"
                      HorizontalAlignment="Stretch"
                      Margin="0,5"
                      VerticalAlignment="Top" />
 
        <cs:ProgressControl Click="ExportProgressCtrl_Click"
                            FontSize="16"
                            FontWeight="Bold"
                            Grid.Column="0"
                            Grid.Row="2"
                            Height="55"
                            Margin="0,5"
                            x:Name="ExportProgressCtrl"
                            TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                            Visibility="Collapsed" />
 
        <Grid Grid.Column="1"
              Grid.Row="0"
              Grid.RowSpan="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="65" />
                <RowDefinition Height="65" />
                <RowDefinition Height="65" />
                <RowDefinition Height="65" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="65" />
                <RowDefinition Height="65" />
            </Grid.RowDefinitions>
            <Button Click="SearchButton_Click"
                    Content="Search"
                    FontSize="16"
                    FontWeight="Bold"
                    Grid.Row="0"
                    IsDefault="True"
                    IsEnabled="{Binding Converter={StaticResource NotBool}, Path=IsSearching, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                    Margin="5"
                    Name="SearchButton"
                    TabIndex="8" />
            <Button Click="ClearButton_Click"
                    Content="Clear"
                    FontSize="16"
                    FontWeight="Bold"
                    Grid.Row="1"
                    IsEnabled="{Binding Converter={StaticResource NotBool}, Path=IsSearching, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                    Margin="5"
                    Name="ClearButton"
                    TabIndex="9" />
            <Button Click="InsertButton_Click"
                    Content="Insert"
                    FontSize="16"
                    FontWeight="Bold"
                    IsEnabled="{Binding Path=OkToInsertHotListEntry, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                    Grid.Row="2"
                    Margin="5"
                    Name="InsertButton"
                    TabIndex="10" />
            <Button Click="SaveCriteriaButton_Click"
                    FontSize="16"
                    FontWeight="Bold"
                    Grid.Row="3"
                    IsEnabled="{Binding Path=OkToSaveCriteria, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                    Margin="5"
                    Name="SaveCriteriaButton"
                    TabIndex="11">
                <Button.Content>
                    <TextBlock Text="Save Search"
                               TextAlignment="Center"
                               TextWrapping="Wrap" />
                </Button.Content>
            </Button>
            <TextBlock FontSize="16"
                       FontWeight="Bold"
                       Foreground="{DynamicResource TextForeground}"
                       Grid.Row="5"
                       Margin="5"
                       Text="Number of Matches:"
                       TextAlignment="Center"
                       TextWrapping="Wrap" />
            <TextBlock FontSize="16"
                       FontWeight="Bold"
                       Foreground="{DynamicResource TextForeground}"
                       Grid.Row="6"
                       Margin="6"
                       Text="Hot List Entries:"
                       TextAlignment="Center"
                       TextWrapping="Wrap" />
            <TextBlock FontSize="16"
                       FontWeight="Bold"
                       Foreground="{DynamicResource TextForeground}"
                       Grid.Row="7"
                       Margin="5,0,5,10"
                       Style="{StaticResource FlashBlockText}"
                       Text="{Binding Converter={StaticResource IntConverter}, ConverterParameter='#,##0', Path=NoHotListEntries, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                       TextAlignment="Center"
                       TextWrapping="Wrap" />
            <TextBlock FontSize="16"
                       FontWeight="Bold"
                       Foreground="{DynamicResource TextForeground}"
                       Grid.Row="8"
                       Margin="5"
                       Text="Reads:"
                       TextAlignment="Center"
                       TextWrapping="Wrap" />
            <TextBlock FontSize="16"
                       FontWeight="Bold"
                       Foreground="{DynamicResource TextForeground}"
                       Grid.Row="9"
                       Margin="5,0,5,10"
                       Style="{StaticResource FlashBlockText}"
                       Text="{Binding Converter={StaticResource IntConverter}, ConverterParameter='#,##0', Path=NoReads, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
                       TextAlignment="Center"
                       TextWrapping="Wrap" />
            <Button Click="ExportButton_Click"
                    Content="Export"
                    FontSize="16"
                    FontWeight="Bold"
                    Grid.Row="11"
                    Margin="5"
                    Name="ExportButton"
                    TabIndex="12">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource CombineBools}" ConverterParameter="AND">
                        <Binding Path="NoReads"        RelativeSource="{RelativeSource AncestorType={x:Type cs:Searcher}}" Converter="{StaticResource GreaterOrEqual}" ConverterParameter="0" />
                        <Binding Path="IsLoadingReads" RelativeSource="{RelativeSource AncestorType={x:Type cs:Searcher}}" Converter="{StaticResource NotBool}" />
                        <Binding Path="IsExporting"    RelativeSource="{RelativeSource AncestorType={x:Type cs:Searcher}}" Converter="{StaticResource NotBool}" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
            <Button Click="CloseButtonClicked"
                    Content="Close"
                    FontSize="16"
                    FontWeight="Bold"
                    Grid.Row="12"
                    HorizontalAlignment="Right"
                    Margin="5"
                    Name="CloseButton"
                    TabIndex="13"
                    Width="100" />
        </Grid>
    </Grid>
</UserControl>


Tony
0
Maya
Telerik team
answered on 18 Feb 2013, 08:17 AM
Hello Tony,

Did you try following the second suggested approach - with predefining the default keyboard command provider ? Do you get the same results ?  

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 19 Feb 2013, 01:30 PM
Yes, I tried the default keyboard command provider and I get the same results.
0
Tony
Top achievements
Rank 1
answered on 28 Feb 2013, 08:19 PM
Can I provide any more information?  How can we resolve this issue?
0
Maya
Telerik team
answered on 01 Mar 2013, 03:41 PM
Hi Tony,

Can you share what the implementation of your custom keyboard command provider is ? What is the exact behavior that you get ?  

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 14 Mar 2013, 12:36 PM
Sorry it took me so long to get back to you after I asked for help.  We're in the middle of pushing out a release to end users and its been crazy busy.

Here's the custom keyboard command provider I wrote:

public class CustomKeyboardCommandProvider : DefaultKeyboardCommandProvider {
 
    private Dictionary<Key, List<ICommand>> KeyMap;
 
    public CustomKeyboardCommandProvider( GridViewDataControl grid )
        : base( grid ) {
        KeyMap = new Dictionary<Key, List<ICommand>>();
    }
 
    public void AddCommand( Key key, ICommand command ) {
        if ( !KeyMap.ContainsKey( key ) ) {
            KeyMap.Add( key, new List<ICommand>() );
        }
 
        KeyMap[ key ].Add( command );
    }
 
    public void ClearCommands( Key key ) {
        if ( KeyMap.ContainsKey( key ) ) {
            KeyMap[ key ].Clear();
        } else {
            KeyMap.Add( key, new List<ICommand>() );
        }
    }
 
    public override IEnumerable<ICommand> ProvideCommandsForKey( Key key ) {
        IEnumerable<ICommand> map = null;
 
        if ( KeyMap.ContainsKey( key ) ) {
            // It does.  Return the ICommands for this key.
            map = KeyMap[ key ];
        } else {
            // It does not.  Call the base class's method and return its result.
            map = base.ProvideCommandsForKey( key );
        }
 
        return map;
    }
 
    public void RemoveCommand( Key key, ICommand command ) {
        if ( KeyMap.ContainsKey( key ) ) {
            if ( KeyMap[ key ].Contains( command ) ) {
                KeyMap[ key ].Remove( command );
            }
        }
    }
}

And here's the code that is used to initialize everything in the constructor:
CustomKeyboardCommandProvider hotListProvider = new CustomKeyboardCommandProvider( HotListEntriesGrid );
CustomKeyboardCommandProvider   readsProvider = new CustomKeyboardCommandProvider(          ReadsGrid );
HotListEntriesGrid.KeyboardCommandProvider = hotListProvider;
         ReadsGrid.KeyboardCommandProvider =   readsProvider;
 
hotListProvider.AddCommand( Key.Enter, CarSystemCommands.DisplayEditHotListEntry );
  readsProvider.AddCommand( Key.Enter, CarSystemCommands.DisplayEditRecordDetails );

As you can see, it's pretty straight forward.

I don't know what the problem is, but it's frustrating that the Enter key is ignored unless the focus is on a row of the RadGridView.

Tony
0
Maya
Telerik team
answered on 19 Mar 2013, 03:31 PM
Hello Anthony,

Since there are some part of the code you provided that I missing in order to compile, I created a small sample project illustrating how you can change the behavior of Enter key.
Could you take a look at it and let me know whether this is similar to the behavior that you require ?  

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 19 Mar 2013, 06:06 PM
Thanks for the example, but it doesn't help.  It doesn't tell me why pressing the enter key when the focus is in a control other than the RadGridView on my form does not result in the Button control with IsDefault = true raising its Click event.

Thanks anyway.
0
Maya
Telerik team
answered on 20 Mar 2013, 02:50 PM
Hello Anthony,

I got a bit confused - how is handling the Enter key for the grid related to the default button in your window ? How can the project  I sent be updated so that it reproduces the behavior ? 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 02 May 2013, 03:59 PM
Maya:

Sorry it's taken me so long to get back to you.  We were in a rollout period that got extended a few times.

The form I have contains a default button.  That is, the IsDefault property of that button is set to True.  When you click enter anywhere on the form, I want that button's Click event to fire.  BUT, when the focus is in a RadGridView that is on my form and a row is selected in the RadGridView, I want a custom command I wrote to fire.

This is the behavior I want.  The behavior I'm seeing is different.

Right now, hitting enter anywhere on the form does nothing, except for when the focus is in the RadGridView, and only on the first time that you press enter.  The custom command causes the tab that the form is in to be hidden and another one to be displayed.  When I switch back to the tab with my form, hitting enter does nothing anywhere on the form.

Edit:

I have managed to fix the issue.

What I did was I moved the command binding for my custom action from the UserControl to the RadGridView control.  Having the command bound to the enter key at the UserControl prevented the normal processing for the whole form, including the default Button.  Moving the command binding so it was specific to the RadGridView control allows the rest of the form to treat the enter key normally and only the RadGridView treats it differently.  And it does it every time.
0
Maya
Telerik team
answered on 06 May 2013, 04:00 PM
Hi Anthony,

I might be missing something, but as far as I can see, you have resolved the issue. Am I right or you need any further assistance ? Let me know if I can help you any further.

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tony
Top achievements
Rank 1
answered on 06 May 2013, 04:02 PM
Maya:

Yes, I have resolved the issue.  Thanks for your help.

Tony
Tags
GridView
Asked by
Tony
Top achievements
Rank 1
Answers by
Tony
Top achievements
Rank 1
Maya
Telerik team
Share this question
or