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

AutoSelect Cell in a new Row AFTER Itemssouce was updated

1 Answer 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Valentin asked on 17 Oct 2017, 11:16 AM

Hi,

i have a radgridview on my wpf app. This grids itemssouce is bound to a List of objects in my ViewModel (MVVM).

When i click on a Button a new element is added to the bound list. This creates a new Row in my DataGrid like expected.

Question:
i want to focus the last cell in the new row after the new row was added.

I already have the correct way of doing this (see snippet below) but i dont know WHEN i should execute this code. When the bound items are changed its too early to do this and i cant use events like "LayoutUpdated" because it triggers too often.

Is there any possibility to launch this code AFTER the GridViewRow was Added?

private void OnInitializedGridViewCommand(RadGridView obj)
        {
            obj.Items.CollectionChanged += (sender, e) =>
            {
                var grid = obj as RadGridView;
                var rows = obj.ChildrenOfType<GridViewRow>().ToList();
                if (rows.Count < 1) return;
                var cells = rows[rows.Count - 1].ChildrenOfType<GridViewCell>().ToList();
                var box = cells[cells.Count - 1].ChildrenOfType<RadComboBox>();
                box.First().Focus();
            };
        }

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 19 Oct 2017, 03:43 PM
Hi Valentin,

You can use the grid's RowEditEnded event. It is raised when new data is added to RadGridView . You can read more about the different types of events available of the RadGridView in our documentation. You can also read the Adding new entries article.

I hope you find this helpful. Let me know if I can be of any further assistance.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Valentin
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or