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

Focus Cell After Replacing Row

4 Answers 18 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KWUN WA
Top achievements
Rank 1
KWUN WA asked on 27 Jul 2016, 07:23 PM

Hi,

I have an advanced MVVM scenario with a GridView hosting an ObservableCollection via ItemsSource. The grid has some complicated editing scenarios, and in one case, I need to replace an object in my collection (due to a conversion where the underlying object needs to be converted to a different type). After the underlying object is replaced, the grid is updated as expected. The problem is that I want to preserve focus on the cell that was being edited, so the user can keep typing to continue editing.

This seems to work fine if it's the first row being edited. I have tried hooking into the RowEditEnded event and using grid.ScrollIntoViewAsync() or cell.Focus() without any success.

Please can someone provide any advice?

Thanks!

4 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 29 Jul 2016, 12:06 PM
Hello,

Could you please have a look at this article which demonstrates how to set the current cell of a RadGridView instance by using the CurrentCellInfo class?

As long as you have access to the new item and the column of the current cell, this approach should be applicable to your scenario.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
KWUN WA
Top achievements
Rank 1
answered on 29 Jul 2016, 07:44 PM

Hi Dilyan,

Thanks for your reply. I seem to have got a solution by monitoring the items source for changes and then using ScrolIntoViewAsync. After scrolling is completed, I use the scrollFinishedCallback to call cell.Focus() and cell.IsCurrent = true.

However, there seems to be one more problem with the RadGridView. The items source is bound to an ObservableCollection<Base>. Some of the items are Foo and some are Bar. In cases where all items are Foo, and then I subsequently try to add a Bar, I'm seeing an InvalidCastException somewhere internally in the RadGridView. This seems to prevent the CellEditEnded event from firing.

Any ideas? Thanks!

0
Dilyan Traykov
Telerik team
answered on 01 Aug 2016, 12:56 PM
Hello,

I'm glad to hear that you've found a solution to your first issue.

I am, however, unable to reproduce the second issue you've described. Could you please have a look at the sample project I've attached and let me know if I'm missing something important?

If you're unable to reproduce the issue in the attached project, may I kindly ask you to open a new support ticket and send over a sample project which demonstrates the issue there so that I may further assist you?

I will be awaiting your reply.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
KWUN WA
Top achievements
Rank 1
answered on 03 Aug 2016, 06:29 PM

Hi Dilyan,

Thanks very much for your response and sample project. Indeed it doesn't seem to occur in your sample, and now I'm having trouble reproducing as well. Not sure if something changed on my side.

Will submit a new support ticket if it reoccurs.

Tags
GridView
Asked by
KWUN WA
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
KWUN WA
Top achievements
Rank 1
Share this question
or