Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Get reference of nested RadGridView

$
0
0

Hi,

I have taken a look at the CustomKeyboardCommandProvider, here is mine:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
namespace DyeingControl
{
    class CustomKeyboardCommandProvider : DefaultKeyboardCommandProvider
    {
        private GridViewDataControl parentGrid;
        private DefaultKeyboardCommandProvider defaultKeyboardProvider;
        private CustomKeyboardCommandProvider customKeyboardProvider;
        public CustomKeyboardCommandProvider(GridViewDataControl grid) : base(grid)
        {
            this.parentGrid = grid;
        }
        public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
        {
            List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
            if (key == Key.Enter)
            {
                commandsToExecute.Clear();
                commandsToExecute.Add(RadGridViewCommands.SelectCurrentItem);
            }
            return commandsToExecute;
        }
    }
}

 

And here I set it to the RadGridView:

 

RadGridView gvMachineType = null;
privatevoidcbMachineType_DropDownOpened(objectsender, EventArgs e)
{
    var comboBox = sender asRadComboBox;
    if(comboBox != null)
    {
        var popup = comboBox.ChildrenOfType<Popup>().FirstOrDefault();
        if(popup != null)
        {
            var popUpContent = popup.Child asFrameworkElement;
            if(popUpContent != null)
            {
                gvMachineType = popUpContent.ChildrenOfType<RadGridView>().FirstOrDefault();
                if(gvMachineType != null)
                {
                    gvMachineType.KeyboardCommandProvider = new CustomKeyboardCommandProvider(gvMachineType);
                    Dispatcher.BeginInvoke(newAction(() =>
                    {
                        gvMachineType.Focus();
                    }));
                }
            }
        }
    }
}

 

Is this ok? Or should I do it in another way? When I debug it, the comipler runs through the CustomKeyboardCommandProvider Code and all is ok...but the behavior is still the same...

 


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>