Prevent select all (Ctrl+A )

4 posts, 0 answers
  1. Leon
    Leon avatar
    2 posts
    Member since:
    Jun 2015

    Posted 16 Jun 2015 Link to this post

    Hello,

    I would like to prevent user from using select all Ctrl+A.

    I tryed to ovveride this behavior through command binding but it didn't work 

     Thank you .

     

     

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Jun 2015 Link to this post

    Hello,

    You can try subscribing for the KeyDown event of the FrameworkElement directly and handle the key combination:

    this.AddHandler(FrameworkElement.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);

     Then, you can modify the selection:
    private void OnKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
        if (e.Key == Key.A && Keyboard.Modifiers == ModifierKeys.Control)
        {
            clubsGrid.UnselectAll();
            e.Handled = true;
        }
    }

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Leon
    Leon avatar
    2 posts
    Member since:
    Jun 2015

    Posted 16 Jun 2015 in reply to Dimitrina Link to this post

     

     Thank you.

    I don't want to unselect anyhing.

    All I want is to prevent grid from handling select all.

  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Jun 2015 Link to this post

    Hi,

    The SelectAll command is an ApplicationCommand and it cannot be canceled from RadGridView level.

    A workaround to prevent the selection would be to subscribe for the SelectionChanging event and Cancel it base on a Boolean flag.
    For example:
    private bool IsSelectAllCommandExecuted;
    public MainWindow()
    {
        InitializeComponent();
        this.AddHandler(RadGridView.PreviewKeyDownEvent, new KeyEventHandler(OnPreviewKeyDown), true);
        this.clubsGrid.SelectionChanging += this.OnSelectionChanging;
     
    void OnSelectionChanging(object sender, SelectionChangingEventArgs e)
    {
        e.Cancel = this.IsSelectAllCommandExecuted;
        this.IsSelectAllCommandExecuted = false;
    }
     
    private void OnPreviewKeyDown(object sender, KeyEventArgs e)
    {
        this.IsSelectAllCommandExecuted = e.Key == Key.A && KeyboardModifiers.IsControlDown;
    }

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top