Unable to set focus to sfdatagrid when entering form

Hi to all,

I have a form "MainFormNext" with the value isMDIContainer=true. Inside this form there is a TabbedMDIManager.

When starting up the form I already open the child forms for the tabbedmdimanager:
Private Sub MainFormNext_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   MainFormNextSettingsRecords.Show()
End Sub

The form "MainFormNextSettingsRecords" is a mdi child contains a sfdatagrid and some textfields beside as additional controls. There I use the following code to focus in the sfdatagrid:
Private Sub MainFormNextSettingsRecords_Enter(sender As Object, e As EventArgs) Handles MyBase.Enter
   Me.SfDataGrid1.Focus()
   Me.SfDataGrid1.TableControl.Select()
   Console.WriteLine(Me.ActiveControl)
End Sub

When I now start form "MainFormNext" and select the tab of the form "MainFormNextSettingsRecords" the sfdatagrid get focus (according to "me.activecontrol" value: "Syncfusion.WinForms.DataGrid.TableControl") but I am not able to scroll via keyboard through the records in the grid (up down arrow keys). Instead after the first "arrow down" press on the keyboard directly a textbox field is then focused.

When I have a button on my form and set as code the focus() and select() as in the ENTER sub, then the grid is selected and I am able to scroll with key up/down.

Is there any solution for this? I also want to focus directly the datagrid and be able to use the keyboard up/down arrows when form becomes active via tabbedmdimanager selection.

thx
Norbert

3 Replies

SS Susmitha Sundar Syncfusion Team April 20, 2020 12:29 PM UTC

Hi Norbert , 

Thank you for using Syncfusion controls. 

You can navigate the SfDataGrid rows by arrow keys, when selection is enable in SfDataGrid. You cant navigate without the current cell. Please use the below code to enable the current cell. 

private void Form1_Enter(object sender, EventArgs e) 
{ 
     this.sfDataGrid1.Focus(); 
     this.sfDataGrid1.TableControl.Select(); 
     this.sfDataGrid1.MoveToCurrentCell(new Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex(1, 0)); 
     
 } 



Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 



NG Norbert Göpel April 21, 2020 12:47 PM UTC

thx a lot. works


SS Susmitha Sundar Syncfusion Team April 22, 2020 09:13 AM UTC

Hi Norbert, 
 
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