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

Set focus of newly added row

3 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Afsal
Top achievements
Rank 1
Afsal asked on 29 Dec 2011, 11:28 AM
Hi,
I am using radgrid and setting the ItemsSource to a collection. When a new item is added to this collection it will create a new empty row in the radgrid. But I am not able to set focus on this newly added row. I need to scroll down to find the newly added row. How can I set focus to the newly added row? I am using MVVM.
Below are the code snippets,
xaml -<telerikGrid:RadGridView ShowGroupPanel="False" ColumnWidth="*"

Name="radSummaryLayout" AutoGenerateColumns="False" ItemsSource="{Binding CollectionName}" Height="Auto"

ScrollMode="RealTime" AutoExpandGroups="False" CanUserDeleteRows="False" CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" ShowColumnHeaders="True" BorderBrush="#FF7C87B1" BorderThickness="1" IsFilteringAllowed="False" AllowDrop="False">

In ViewModel- the following code executes in a button click event.
Dim eMem As New Item
CollectionName.Add(eMem)

Thanks in advance,
Afsal

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Dec 2011, 09:49 AM
Hello Afsal,

You could scroll to the newly added row, using a method which is called ScrollIntoViewAsync(). It takes an action as parameter and this action will be performed when all requested scroll operations are completed. You can take a look at the following snippet for a reference how to use this method in your scenario:

grid.ScrollIntoViewAsync(row,  column,
                    (r) =>
                    {
                        GridViewRow row = r as GridViewRow;
                        if(row != null)
                        {
                              row.Cells[0].Focus();
                              cell.IsSelected = true;
                              cell.IsCurrent = true;
                              cell.ParentRow.GridViewDataControl.CurrentColumn = cell.Column;
                              cell.ParentRow.GridViewDataControl.CurrentItem = cell.DataContext;
                        }
                    });

Let me know if this doesn't help.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Afsal
Top achievements
Rank 1
answered on 30 Dec 2011, 12:13 PM
Hi Didie,

Thanks for your reply. I tried that but not worked. Since i am adding the collection in viewmode I tried to call the ScrollIntoViewAsync in RowLoaded event. I tried the below code, 

grd.ScrollIntoViewAsync(e.Row,

 

Function(f)

Dim row As GridViewRow = TryCast(e.Row, GridViewRow)

If row IsNot Nothing Then

Dim cell As GridViewCell = row.Cells(0)

row.Cells(0).Focus()

cell.IsSelected = True

 

cell.IsCurrent =

True

 

cell.ParentRow.GridViewDataControl.CurrentColumn = cell.Column

cell.ParentRow.GridViewDataControl.CurrentItem = cell.DataContext

 

                                                              

End If

End Function)


Am I missing something? Can you give me a sample application?
Many thanks,
Afsal

 

 
0
Dimitrina
Telerik team
answered on 30 Dec 2011, 01:41 PM
Hi Afsal,

 I would need more information in order to find out why this code is not working at your end. Could you please tell me how is your ItemsSource defined? When do you add a new item - on a button click maybe?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Afsal
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Afsal
Top achievements
Rank 1
Share this question
or