Focus AddNewRow after committing row

Greetings,

After successfully committing a SfDataGrid's AddNewRow data, I would like to make the now cleared AddNewRow to be the active row with a specified cell set to BeginEdit. This is to negate the need to continually having to click a cell in that row to make it active. I have tried using the SfDataGrid.View's CollectionChanged event to achieve this, but don't seem to be able to get this working; the focus always seems to end up with the newly added row. I have used the following statements without success:

Dim columnIndex = SfDataGrid1.TableControl.ResolveToScrollColumnIndex(SfDataGrid1.Columns.IndexOf(SfDataGrid1.Columns("MyColumn")))
SfDataGrid1.MoveToCurrentCell(New RowColumnIndex(SfDataGrid1.GetAddNewRowIndex, columnIndex))
SfDataGrid1.BeginEdit()

Is there a way to achieve this?

I'm using VB.Net and a DataTable with WinForms 18.3.0.47.


7 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team December 22, 2020 12:10 PM UTC

Hi Jeremy, 

Thank you for using Syncfusion controls. 

We are little unclear with your requirement we suspect you need the AddNewRow is in BeginEdit stage even after committing the new record. If yes you can achieve this by SfDataGrid.TableControl.BeginInvoke method like below, 
sfDataGrid.TableControl.BeginInvoke(New Action(Function() AnonymousMethod1(e))) 
Private Function AnonymousMethod1(ByVal e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) As Object 
    Dim columnIndex = sfDataGrid.TableControl.ResolveToScrollColumnIndex(sfDataGrid.Columns.IndexOf(sfDataGrid.Columns("OrderID"))) 
    Dim rowIndex = sfDataGrid.GetAddNewRowIndex() 
    sfDataGrid.MoveToCurrentCell(New RowColumnIndex(rowIndex, columnIndex)) 
    sfDataGrid.CurrentCell.BeginEdit() 
    Return Nothing 
End Function 

We have prepared the sample for the same, 

 
Else can you please explain your scenario. We hope it helps please let us know f you need further assistance. 

Regards,
Dhanasekar Mohanraj. 


Marked as answer

JE Jeremy December 22, 2020 12:55 PM UTC

Hi Dhanasekar,

You were correct in your assumption. The supplied snippet works perfectly.

Thanks for the quick response.

Regards

Jeremy


VS Vijayarasan Sivanandham Syncfusion Team December 23, 2020 06:00 AM UTC

Hi Jeremy, 
 
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, 
Vijayarasan S 



YG Yvo G. December 23, 2021 11:04 AM UTC

This looks great, I'd like to see the same in C# ?



VS Vijayarasan Sivanandham Syncfusion Team December 23, 2021 01:31 PM UTC

Hi Yvo G,

Based on provided information we have prepared the sample for achieve your requirement. 


Please have a look at this sample and let us know if you have any concerns in this.

Regards, 
Vijayarasan S 



YG Yvo G. December 24, 2021 12:17 PM UTC

This indeed helps me out. Remarkably my own OLEDB-based project doesn't trigger any "sfDataGrid1.View.Records.CollectionChanged" event from AddNewRow activities, so I had to make some changes and variations in order to make things work for me.
Looking good so far. Thanks a lot !



VS Vijayarasan Sivanandham Syncfusion Team December 27, 2021 03:28 AM UTC

Hi Yvo G,

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,
Vijayarasan S


Loader.
Up arrow icon