GanttView delete item with DEL-Key

2 Answers 111 Views
GanttView
Marco
Top achievements
Rank 1
Iron
Iron
Iron
Marco asked on 01 Mar 2022, 09:37 AM

I use the RadGanttView. The GanttView is quit big and it has many items. The items are deletable. So I want to delete them with the DELETE key. I tried to add the "PreviewKeyDown" event and check if the delete Key is klicked. But the event isn't thrown.

<telerik:RadGanttView x:Name="GanttDiagramm" PreviewKeyDown="GanttDiagramm_OnKeyDown">

I use the Office2013 Theme. 

I tried the same with a testproject. There the event is thrown sometimes. But not everytime. Quiet curios.

How can I delete a collection of items with the DEL-Key?

2 Answers, 1 is accepted

Sort by
1
Accepted
Dilyan Traykov
Telerik team
answered on 02 Mar 2022, 10:56 AM

Hello Marco,

Thank you for the provided code snippet.

Based on it, I set up a small sample project to test this, however, both the Delete and Del keys correctly. Please note, however, that for the Del key to work as expected, the NumLock should be disabled.

Please find attached the project I set up. For it to work in accordance with the MVVM pattern, I've used the EventToCommandBehavior helper class:

            <telerik:EventToCommandBehavior.EventBindings>
                <telerik:EventBinding EventName="PreviewKeyDown" 
                                      Command="{Binding DeleteTaskCommand}" 
                                      PassEventArgsToCommand="True"
                                      RaiseOnHandledEvents="True" />
            </telerik:EventToCommandBehavior.EventBindings>

Please have a look and let me know if this project also behaves as expected at your end and whether you can use the same approach in your original application.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Marco
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Mar 2022, 02:21 PM

Hello Dilyan

Thanks for your answer.

I tried your solution. It didnt't work. So I analysed it again. And I think I found the problem. My GanttView must be in a ScrollViewer, because it can be very big. 

And this is the problem, the scrollviewer is always selected. Even if I click on a task.

I tried the described with your project:

    <ScrollViewer>
        <Grid>
            <telerik:RadGanttView x:Name="GanttDiagramm" VisibleRange="{Binding VisibleRange}" TasksSource="{Binding Tasks}">
                <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding EventName="PreviewKeyDown" 
                                      Command="{Binding DeleteTaskCommand}" 
                                      PassEventArgsToCommand="True"
                                      RaiseOnHandledEvents="True" />
                </telerik:EventToCommandBehavior.EventBindings>
                <telerik:RadGanttView.Columns>
                    <telerik:TreeColumnDefinition Header="Title" MemberBinding="{Binding Title}" IsFrozenColumn="True" ColumnWidth="200" />
                </telerik:RadGanttView.Columns>
            </telerik:RadGanttView>
        </Grid>
    </ScrollViewer>

And then the event is never called. If I create the PreviewKeyDown event on the Scrollviewer it is executed all the time. Is this a selection bug? Can I solve that somehow?

Thanks, Marco

Dilyan Traykov
Telerik team
commented on 08 Mar 2022, 09:30 AM

Hello Marco,

Thank you for the clarification.

Upon further investigation, I found that this behavior occurs because the ScrollViewer is focusable and receives the focus when the RadGanttView control is clicked. As a result, the ScrollViewer handles and processes keys.

As a solution, I suggest that you set the ScrollViewer's Focusable property to False.
<ScrollViewer Focusable="False">
Please give this a try and let me know if this works for you.
Marco
Top achievements
Rank 1
Iron
Iron
Iron
commented on 08 Mar 2022, 09:32 AM

Hey Dilyan, I tried it rightnow and it works perfectly. Thank you so much!
Tags
GanttView
Asked by
Marco
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dilyan Traykov
Telerik team
Marco
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or