Focus Cell After Replacing Row

5 posts, 0 answers
  1. KWUN WA
    KWUN WA avatar
    6 posts
    Member since:
    Aug 2015

    Posted 27 Jul Link to this post

    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!

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 29 Jul Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. KWUN WA
    KWUN WA avatar
    6 posts
    Member since:
    Aug 2015

    Posted 29 Jul Link to this post

    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!

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 01 Aug Link to this post

    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.
  6. KWUN WA
    KWUN WA avatar
    6 posts
    Member since:
    Aug 2015

    Posted 03 Aug in reply to Dilyan Traykov Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready