We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Cannot select all rows on Ctrl + A

Thread ID:

Created:

Updated:

Platform:

Replies:

124163 May 22,2016 06:16 PM May 26,2016 11:44 PM WPF 7
loading
Tags: SfDataGrid
Andrey
Asked On May 22, 2016 06:16 PM

Hello,

I have experienced unexpected behavior in SfDataGrid, where the standard Windows Ctrl+A combination is not available. I spent lots of time trying to get it to work, but it seems blocked at some level. I noticed that In the provided WPF samples, Ctrl+A (SelectAll command) was also doing nothing. When I command bind to other key combinations, like Ctrl+P in the example below, I can run the command, but I need users to have the standard Windows expericence. How can use Ctrl+A to select all grid rows?

public static RoutedCommand MyCommand = new RoutedCommand();
...
MyCommand.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Control));

private void SelectAllCommandEx(object sender, ExecutedRoutedEventArgs e)
        {
            sfDataGrid.SelectRows(2, sfDataGrid.GetRecordsCount());
        }

Another bug I encountered was that the filter row (FilterRowPosition="FixedTop") in the sfDataGrid was also selected with SelectRows(1, EndRow), which is unusual, because i cannot imagine a scenario in which the Filter Row should be selected alongside normal rows. The filter row also seems to get the row index, which requires adding offsets to regular rows.

Srinivasan Vasu [Syncfusion]
Replied On May 24, 2016 02:29 AM

Hi Andrey, 
 
Query 1[Ctrl + A]: 
 
We have analyzed your query and the SfDataGrid will process Keyboard and Mouse interactions based on GridCell. Hence, the RoutedCommand is not worked for Window. But you can achieve your requirement by overriding ProcessKeyDown method from GridSelectionController in SfDataGrid. 
 
Please refer the below code example. 
 
public class Controller: GridSelectionController 
    { 
        private SfDataGrid sfdatagrid; 
 
        public Controller(SfDataGrid sfdatagrid) : base(sfdatagrid) 
        {            
            this.sfdatagrid = sfdatagrid;             
        } 
        protected override void ProcessKeyDown(KeyEventArgs args) 
        {             
         if(Keyboard.IsKeyDown(Key.A) && SelectionHelper.CheckControlKeyPressed()) 
           { 
               this.sfdatagrid.SelectionController.ClearSelections(false); 
               this.sfdatagrid.SelectRows(1, this.sfdatagrid.GetLastDataRowIndex());           
           }            
        } 
    } 
 
Query 2[FilterRowPosition]: 
 
 
In SfDatagrid, we will process the selection and navigation for other than data rows like FilerRow, AddNewRow and UnboundRow which is default behavior of SfDataGrid. 
If you want to process the selection excluding the FilterRow in SelectRows method, please use GridFirstDataRowIndex helper method instead proceeding the value directly. 
 
Please refer the below code example. 
// Select DataRows 
// Helper methods will be in Syncfusion.UI.Xaml.Grid.Helpers 
 
this.sfdatagrid.SelectRows(this.sfdatagrid.GetFirstDataRowIndex, this.sfdatagrid.GetLastDataRowIndex()); 
 
 
 
 
 
Sample Location: SelectRow 
 
Regards, 
Srinivasan 
 



Srinivasan Vasu [Syncfusion]
Replied On May 24, 2016 10:05 AM

Hi Andrey,  
Please ignore our previous update. 
Query 1[Ctrl + A]:  
  
We have analyzed your query and the SfDataGrid will process Keyboard and Mouse interactions based on GridCell. Hence, the RoutedCommand is not worked for Window. But you can achieve your requirement by overriding ProcessKeyDown method from GridSelectionController in SfDataGrid.  
  
Please refer the below code example.  
  
 
this.sfdatagrid.SelectionController  = new Controller (sfdatagrid); 
 
public class Controller: GridSelectionController  
    {  
        private SfDataGrid sfdatagrid;  
  
        public Controller(SfDataGrid sfdatagrid) : base(sfdatagrid)  
        {             
            this.sfdatagrid = sfdatagrid;              
        }  
        protected override void ProcessKeyDown(KeyEventArgs args)  
        {              
         if(Keyboard.IsKeyDown(Key.A) && SelectionHelper.CheckControlKeyPressed())  
           {  
               this.sfdatagrid.SelectionController.ClearSelections(false);  
               this.sfdatagrid.SelectRows(1, this.sfdatagrid.GetLastDataRowIndex());            
           }             
        }  
    }  
  
Query 2[FilterRowPosition]:  
  
  
In SfDatagrid, we will process the selection and navigation for other than data rows like FilerRow, AddNewRow and UnboundRow which is default behavior of SfDataGrid.  
If you want to process the selection excluding the FilterRow in SelectRows method, please use GridFirstDataRowIndex helper method instead proceeding the value directly.  
  
Please refer the below code example.  
// Select DataRows  
// Helper methods will be in Syncfusion.UI.Xaml.Grid.Helpers  
  
this.sfdatagrid.SelectRows(this.sfdatagrid.GetFirstDataRowIndex(), this.sfdatagrid.GetLastDataRowIndex());  
  
  
  
  
  
Sample Location: SelectRow  
  
Regards,  
Srinivasan  
  
 


Andrey
Replied On May 25, 2016 10:57 AM

Srinivasan , thank you for your reply. I have tested the solution you offered for Query 1, but it seems suboptimal, because although it does allow to select rows on Ctrl+A, it breaks all other key down events in sfDataGrid (like Key.Down/Up, Page.Down/Up, Home, End, etc).

ProcessKeyDown is a large method with complex logic, so it seems to be an overkill to try and recreate it all in the override, just for the sake of SelectAll. Is there any simpler solution to the Ctrl+A problem?

Srinivasan Vasu [Syncfusion]
Replied On May 26, 2016 02:13 AM

Hi Andrey, 
Sorry about the inconvenience and please ignore our previous code example. Please find the correct one below. 
C# 
this.sfdatagrid.SelectionController = new Controller(sfdatagrid); 
 
public class Controller : GridSelectionController 
    {         
        public Controller(SfDataGrid sfdatagrid) : base(sfdatagrid) 
        { 
 
        }        
        protected override void ProcessKeyDown(KeyEventArgs args) 
        { 
            if (Keyboard.IsKeyDown(Key.A) && SelectionHelper.CheckControlKeyPressed()) 
            { 
                this.DataGrid.SelectionController.ClearSelections(false); 
                this.DataGrid.SelectRows(1, 10); 
                return;                                    
            } 
            base.ProcessKeyDown(args);  // Base method calling 
        } 
    } 
 
 
Sample Location: SelectRows 
 
Regards, 
Srinivasan 
 



Srinivasan Vasu [Syncfusion]
Replied On May 26, 2016 02:27 AM

Hi Andrey, 
 
Sorry about the inconvenience and please ignore our previous code example. Please find the correct one below. 
 
C# 
this.sfdatagrid.SelectionController = new Controller(sfdatagrid); 
 
public class Controller : GridSelectionController 
    {         
        public Controller(SfDataGrid sfdatagrid) : base(sfdatagrid) 
        { 
 
        }        
        protected override void ProcessKeyDown(KeyEventArgs args) 
        { 
            if (Keyboard.IsKeyDown(Key.A) && SelectionHelper.CheckControlKeyPressed()) 
            { 
                this.DataGrid.SelectionController.ClearSelections(false); 
                this.DataGrid.SelectRows(1, this.DataGrid.GetLastDataRowIndex()); 
                return;                                    
            } 
            base.ProcessKeyDown(args);  // Base method calling 
        } 
    } 
 
 
 
Sample Location: SelectRows 
 
Regards,
Srinivasan 
 


Andrey
Replied On May 26, 2016 10:24 AM

Srinivasan,

thank you for the updated code! It is working great now.

Jai Ganesh S [Syncfusion]
Replied On May 26, 2016 11:44 PM

Hi Andrey, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;