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

Prevent select all (Ctrl+A )

3 Answers 298 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Leon
Top achievements
Rank 1
Leon asked on 16 Jun 2015, 07:32 AM

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 .

 

 

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 16 Jun 2015, 11:57 AM
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
0
Leon
Top achievements
Rank 1
answered on 16 Jun 2015, 12:15 PM

 

 Thank you.

I don't want to unselect anyhing.

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

0
Dimitrina
Telerik team
answered on 16 Jun 2015, 01:31 PM
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
Tags
GridView
Asked by
Leon
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Leon
Top achievements
Rank 1
Share this question
or