[Solved] - How to alway set focus SfForm to using keydown on Datagrid?

For some reason I want the Form.show (modeless) instead of showdialog(modal), combined with the keydown override, I want when pressing ctrl + A all the datagrid rows will be selected, however in some cases (because the form shows modeless so the command is executed on the main form), what should I do to make the command always execute if the form is showing?
Here is the code I am using:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (SFForm.Visible == true)
        SFForm.Activate(); //Focus SFForm
    if ((keyData.HasFlag(Keys.A) && keyData.HasFlag(Keys.Control)))
    {
        this.f_DataGrid1.SelectionMode = GridSelectionMode.Extended;
        f_DataGrid1.SelectAll();
        return true;
    }
    else if ()
    {
    }

    return base.ProcessCmdKey(msg, keyData);
}

6 Replies

SS Susmitha Sundar Syncfusion Team May 4, 2020 03:04 PM UTC

Hi GridLock,  
  
Thank you for using Syncfusion controls. 
  
We have prepared the sample based on your scenario. While execute the keydown method using Ctrl + A, child form always gets focused.  
  
 
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us back with the following details,  
  
·          Replication procedure.      
·          Issue reproducing video (if possible)  
·          Syncfusion update version  
 
  
It will be helpful for us to check on it and provide you the solution at the earliest.    
  
Regards,  
Susmitha S  



TG The GridLock May 4, 2020 06:22 PM UTC

Hi Durai,
Thanks for the sample file, I will try it.


SS Susmitha Sundar Syncfusion Team May 5, 2020 05:44 AM UTC

Hi GridLock, 
 
Thanks for the update. 
 
We will wait to hear from you. 
 
Regards, 
Susmitha S 



TG The GridLock May 5, 2020 10:18 AM UTC

Hi Susmitha,
Thanks! Maybe I have amnesia ^^ Sr.


TG The GridLock May 6, 2020 02:43 AM UTC

Hi Susmitha,
After reviewing it, I realized that I was mistaken to say that it was the main form, it was another frame not a winform (such as a ribbon).
I searched and tried hook. It is working for me now.
Problem solved!


SS Susmitha Sundar Syncfusion Team May 6, 2020 05:28 AM UTC

Hi GridLock, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Susmitha S 


Loader.
Up arrow icon