Programmatically edit and typing without having to click

I add a record to my sfDataGrid, refresh and call BeginEdit on the last row on the new empty cell:

var record = new TipoSpecieSQ { TipoSpecieDesc = "" };
tipiSpecieDbSet.Add(record);
sfDataGrid2.View.Refresh();
RowColumnIndex rowColumnIndex = new RowColumnIndex(tipiSpecieDbSet.records.Count + 1, 1);
sfDataGrid2.MoveToCurrentCell(rowColumnIndex);
sfDataGrid2.CurrentCell.BeginEdit();

it works, and the correct cell gets a blue border, but if I start to type the cell remains empty.
If I click on the cell, then I can type data in.

I tried sfDataGrid2.Focus() and sfDataGrid2.Select(), but same result.

What should I set to be able to add and type directly, without having to click on the cell?

Thanks,
Mattia

1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team February 24, 2021 06:09 PM UTC

Hi Mattia,

Thank you for contacting Syncfusion support.

Your requirement can be achieved by customization in Paint event in SfDataGrid.TableControl. Please refer the below code snippet for your reference, 
int count = 0; 
private void TableControl_Paint(object sender, PaintEventArgs e) 
{ 
            if (count == 0) 
            { 
                sfDataGrid1.Focus(); 
                sfDataGrid1.MoveToCurrentCell(new RowColumnIndex(sfDataGrid1.View.Records.Count, 0)); 
                sfDataGrid1.CurrentCell.BeginEdit(); 
                count++; 
            } 
 
} 
 
private void button1_Click(object sender, EventArgs e) 
{ 
            var record = new TipoSpecieSQ { TipoSpecieDesc = "" }; 
            Orders.Add(record); 
            //Recall the CurrentCellBeginEdit while AddNewRow 
            count = 0;             
} 

Sample Link: https://www.syncfusion.com/downloads/support/forum/162898/ze/Sample799795742

Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon