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

Binding KeyUp Event with Parameter

9 Answers 610 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Iron
Iron
Valentin asked on 15 Jan 2018, 10:06 AM

Hello Telerik,

 

I have a RadGridView and I set to it an EventBinding like this :

<telerik:EventToCommandBehavior.EventBindings>
    <telerik:EventBinding Command="{Binding CommandDeleteFolderRSP}" EventName="KeyUp"
                   CommandParameter="Delete" />
</telerik:EventToCommandBehavior.EventBindings>

=> I want to bind a command if the user wants to delete the selected row.

 

The problem is that all of the keys are fired the command, not only the 'Delete' key.

What is my error ?

 

Thank you.

9 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Jan 2018, 11:49 AM
Hi Valentin,

In order to achieve this, you can benefit from the built-in Commands that the control provides. This is demonstrated in the Commands WPF Demo and in its online equivalent.

Can you please give it a try and let me know how it goes?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 18 Jan 2018, 07:47 AM

Hi Stefan,

 

Thanks for your answer, but if I understand documentations, I must go through in code behind to link the "Delete" keyboard and the Delete RadGridView Command ?

 

I know that I can do the following code :

Private Sub RadGridViewFoldersSettingsRSP_KeyUp(sender As Object, e As KeyEventArgs)
    If e.Key = Key.Delete Then
        Me._vm.CommandDeleteFolderRSP.Execute(Nothing)
    End If
End Sub

 

... But if I can do it in XAML file it's better.

 

Any idea ?

0
Stefan
Telerik team
answered on 22 Jan 2018, 03:24 PM
Hi Valentin,

Thanks for the update.

It seems that I have overlooked that you need to perform the user confirmation on Delete button click. Please, excuse me for this.

In order to achieve such behavior you can utilize the Deleting event instead of the KeyDown one. It will be raised when the user presses the Delete key and you can cancel the deleting operation with it by setting the Cancel property of the event arguments to true. Can you please check this out?

I hope this helps. Let me know in case further assistance is needed.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 23 Jan 2018, 07:55 AM

Hello Stefan,

I don't exactly understand what you mind.

I found the Deleting event but this one created a code in code behind and my question is, is it possible to do this only in xaml ?

If this is why I tried with the EventBinding but this one catch all keys, and not only the Delete key. May be my parameter is bad ?

 

I don't know if I express myself correctly.

 

Thank you !

0
Stefan
Telerik team
answered on 25 Jan 2018, 04:39 PM
Hello Valentin,

To demonstrate what I have in mind, I have prepared a sample application which you can find attached to my post. As you should be able to see, the deleting operation is cancelled if the user tries to delete the item with name Chelsea. The event and the command, respectively, will be triggered when the user presses the Delete key.

Can you please check it out? Does this correspond to your requirements?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 26 Jan 2018, 08:26 AM

Hi Stefan,

Thank you for this project.

It is the behavior that I was expected, but when I'm triying to set it on my project, nothing is done.

 

My Grid :

<telerik:RadGridView x:Name="RadGridViewFoldersSettingsRSP" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserFreezeColumns="False" CanUserInsertRows="False"
                                         CanUserReorderColumns="False" CanUserResizeColumns="True" CanUserResizeRows="False" CanUserSortColumns="False" Height="Auto" HorizontalAlignment="Stretch"
                                         IsReadOnly="True" ItemsSource="{Binding Folders}" Margin="5" MinWidth="400" MinHeight="340" SelectionMode="Single" SelectionUnit="FullRow" ShowGroupPanel="False"
                                         Width="Auto" Grid.Row="1" VerticalAlignment="Stretch" IsFilteringAllowed="False" SelectedItem="{Binding SelectedFolder}" RowIndicatorVisibility="Collapsed"
                                         GroupRenderMode="Flat" >
                        <!--KeyUp="RadGridViewFoldersSettingsRSP_KeyUp"-->
                        <telerik:EventToCommandBehavior.EventBindings>
                            <telerik:EventBinding Command="{Binding CommandDeleteFolderRSP}" EventName="Deleting" PassEventArgsToCommand="True" />
                        </telerik:EventToCommandBehavior.EventBindings>
<!--Columns-->
                    </telerik:RadGridView>

 

My VM :

Public ReadOnly Property CommandDeleteFolderRSP As ICommand
    Get
        Static _command As New CommandImpl(AddressOf DeleteFolderRSP)
        Return _command
    End Get
End Property
Private Sub DeleteFolderRSP(p_parameter As Object)
    If Me.SelectedFolder IsNot Nothing Then
        If (Me.ConfirmBox("text","header") = True) Then
            RSP_DAO.DeleteFolderRSP(Me.SelectedFolder.Folder)
            Me.LoadFoldersAutoprocessor()
        End If
    Else
        Me.ErrorBox("text","error")
    End If
End Sub

 

I put a breakpoint in the DeleteFolderRSP sub but I never enter inside. I tried with CanUserDeleteRows="True" but I have the same result...

What is the problem ?

 

Thank.

0
Stefan
Telerik team
answered on 30 Jan 2018, 03:13 PM
Hello Valentin,

Its strange that the solution is not working on your end. I converted the provided sample application to a VB project and it is working as expected. You can find it attached to my reply.

May I kindly ask you to take a look at it? Does the approach demonstrated in it work as expected on your end?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 31 Jan 2018, 08:16 AM

Hi Stefan,

Thanks for the project in VB, and it's the behavior that I expected.

 

I found why my breakpoint was never attained : although I set CanUserDeleteRows="True", the IsReadOnly="True" property blocks the Deleting event. Therefore, I set IsReadOnly="True" and the breakpoint was found by the debugger.

 

Thank you very much !

 

Valentin.

0
Stefan
Telerik team
answered on 05 Feb 2018, 07:57 AM
Hi Valentin,

I am happy to hear that you have found the solution for your requirement.

Feel free to contact us again should you need other assistance with our components.

All the best,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Valentin
Top achievements
Rank 1
Iron
Iron
Answers by
Stefan
Telerik team
Valentin
Top achievements
Rank 1
Iron
Iron
Share this question
or