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. Image for the cookie policy date

Select first row after getting focus

Hi,

I try to use sfDataGrid as a search windows. I have a simple form with a TextBoxExt and a sfDataGrid.
When typing a value in the TextBox, the grid is filtered by that text.

When one row is left, I want only press enter to select the first value of the row and send it back as my key.
Or when there are multiple rows left, I want to press the down arroy (or tab) to left the TextBox and enter the sfDataGrid.
So I can use the down arrow to go to the record I want, press enter and send the first value back as my key.

It is working now with the mouse. After filtering, I can double click on a row and send back the first value of the row.

And what is working also is after filtering, I click with the mouse on a row, then go with arrow key to the record of my choose, press enter.

What I can not getting work is give the sfDataGrid the same focus as clicking with the mouse on the grid.

With sfDataGrid.Focus() and sfDataGrid1.SelectRows(1,1) or sfDataGrid.SelectCells(record, column), I can not use arrow keys to go to the other records.

So my question is:
How can I set the same focus programmaticaly as clicking with the mouse on a cell.

Thank You,

Gerrit

2 Replies

GS Gerrit Snel December 25, 2018 04:50 AM

Solved it:

            if(e.KeyCode == Keys.Down)
            {
                if(sfDataGrid1.View.Records.Count > 0)
                {
                    this.sfDataGrid1.Focus();
                    this.sfDataGrid1.SelectedItems.Add(this.sfDataGrid1.View.Records[0]);
                    this.sfDataGrid1.TableControl.Select();
                }
            }


JN Jayaleshwari N Syncfusion Team December 26, 2018 06:44 AM

Hi Gerrit, 
 
Thanks for the update. 
Please get in touch if you would require further assistance. 
 
Regards, 
Jayaleshwari N. 


Loader.
Live Chat Icon For mobile
Up arrow icon