This is a migrated thread and some comments may be shown as answers.

Managing the addition of new rows to a DataGrid

2 Answers 131 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 26 Jan 2018, 03:11 PM

I am trying to handle the addition of new rows to a DataGrid by providing the user with an "Add" button. This calls the following simple code, which is intended to add a new row to the ItemSource, Select it, and then BeginEdit on it:

ViewModel.AddReportDue();
ReportsDueGrid.ScrollItemIntoView(ViewModel.SelectedReportDue);
ReportsDueGrid.SelectItem(ViewModel.SelectedReportDue);
ReportsDueGrid.BeginEdit(ReportsDueGrid.SelectedItem);

This works up to a point and I have ensured via the debugger that the SelectedItem in the last statement is indeed the row I have just added, but the BeginEdit always starts at the second row of the grid (see image). I have also tried to BeginEdit on the first item in the underlying collection, again with the same result. Does anyone know of a way of forcing the BeginEdit to target the correct row after the new row is added?

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 30 Jan 2018, 09:47 AM
Hello David,

The observed by you behavior could be considered as an expected one. Basically, after adding new item to the DataGrid the control itself needs some time to rearrange and measure. Because of that trying to edit the item so soon after adding it could cause unexpected behavior. What we could suggest you is to use the "scrollCompleteAction" of the ScrollItemIntoView method and inside ti to invoke the BeginEdit method - thus it will be sure that the added item is arrange and present in the DataGrid.

Please, check the attached sample that demonstrates the described above approach.

Hope this helps.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 30 Jan 2018, 10:08 AM

Thanks. That is really helpful, and is much appreciated.

David

Tags
DataGrid
Asked by
David
Top achievements
Rank 1
Answers by
Nasko
Telerik team
David
Top achievements
Rank 1
Share this question
or