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

Keyboard Command Provider on Child Table

3 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 01 Nov 2017, 04:45 PM

I have several GridViews on my interface and then on one it has a ChildTableDefinition.  I am trying to have the TAB key insert a row if pressed on the end of the last line on each GridView.  I have followed the instructions and created the KeyboardCommandProvider that overrides the ProvideCommandsForKey method. I have then wired up the KeyboardCommandProvider in the code behind

myGrid1.KeyboardCommandProvider = new Commands.TabKeyCommandProvider(myGrid1);

however the definition for my Child Table is done via a DataTemplate

<telerik:RadGridView.ChildTableDefinitions>
    <telerik:GridViewTableDefinition />
 </telerik:RadGridView.ChildTableDefinitions>
 <telerik:RadGridView.HierarchyChildTemplate>
    <DataTemplate>
           <telerik:RadGridView ItemsSource="{Binding custom_identifier}"
                                              x:Name="ChildGrid1"
                                              ShowGroupPanel="False"
                                              AutoGenerateColumns="False">
                          <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding label}"
                                                                            Header="Custom Identifier"
                                                                            IsSortable="True"
                                                                            IsFilterable="False" />
                           </telerik:RadGridView.Columns>
                </telerik:RadGridView>
          </DataTemplate>
 </telerik:RadGridView.HierarchyChildTemplate>

Now as this child Grid is defined in a template, I can not reference it using the x:Name of "ChildGrid1" in the code behind.  So how do I attach the custom Command Provider to this grid?

 

Also - is there an MVVM way of doing this as doing it in Code Behind is not ideal ??

 

Any suggestions welcome

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Nov 2017, 10:38 AM
Hello Paul,

In case I am understanding your requirement correctly, you should be able to benefit from the RowDetails mechanism of the control for meeting this requirement. By doing so, you can access the RadGridView placed within the RowDetailsTemplate, as shown in the Find a control in RowDetailsTemplate help article. Since you need avoid applying this operation in code-behind, you can implement an attached behavior, or use the EventToCommandBehavior.

Would such an approach be feasible for you, or you need to stick to the usage of the Hierarchy of RadGridView?

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
Paul
Top achievements
Rank 1
answered on 02 Nov 2017, 11:48 AM

Hi Stefan

Excellent !!

Thanks for the hint towards using RowDetails instead of a Hierarchy - this has worked for what we needed (and actually looks better on the screen) and I can now attach the custom KeyboardCommandProvider to it.

 

Cheers

Paul

0
Stefan
Telerik team
answered on 06 Nov 2017, 01:07 PM
Hello Paul,

I am happy that the suggested approach meets your requirements.

Do not hesitate to contact us again should you need any other assistance with our components.

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.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Paul
Top achievements
Rank 1
Share this question
or