We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Finding newly inserted row

I am using the GridDataControl for WPF and I am trying to setup a process that does the following:

1) When Adding a record, set focus to column x of the new row.
2) When duplicating a record, set focus to column y of the new row.

I am using an MVVM application and have an observablecollection I am bound to.  The VM will add the new record to the datasource and it shows in the grid.  What I need is to be able to set focus to this new row and then set focus to a specific column in that row.

The grid is sortable so it's possible that the new row is not in position of RowCount -1.  Thus the frustration.  :)

I have been hunting but have had no luck finding a solution.

Any help would be greatly appreciated.

3 Replies

SH Shakul Hameed M Syncfusion Team December 9, 2013 12:45 PM UTC

Hi Joshua,

 

Thanks for contacting Syncfusion.

We have analyzed your query and we can achieve your requirement by using the below code.

 

Please refer the following code snippet.

 

Code Snippet:

void View_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

        {

            if(NotifyCollectionChangedAction.Add==e.Action)

            {           

                var index = e.NewStartingIndex;

                var rowIndex = this.GridDataControl1.Model.ResolvePositionToIndex(index);

                var record=e.NewItems[0] as Person;

 

                var records = this.GridDataControl1.Model.View.Records;

                var result = from c in records

                             where (c.Data as Person).No == record.No

                             select c;

 

                if (result.Count() >= 2)

                {

                    this.GridDataControl1.Model.Grid.CurrentCell.MoveTo(rowIndex,1);                   

                    this.GridDataControl1.Model.Grid.CurrentCell.BeginEdit();

                }

                else

                {

                    this.GridDataControl1.Model.Grid.CurrentCell.MoveTo(rowIndex, 0);

                    this.GridDataControl1.Model.Grid.CurrentCell.BeginEdit();

                }        

            }

        }

 

We can get the exact record position by listening the Collection Changed event, even the grid is in sort.

 

And I have moved the current cell to that new record position by using MoveTo method. If the newly added record contains a unique No means the current cell position moved to the first column,

if it’s a duplicate row, then it moves to the second column.

 

We have prepared a sample based on your requirement. Please find the sample from the below location.

 

Sample: GridDataControl Row Positioning.zip

 

Please let us know, if you have any queries.

 

Thanks,

Shakul Hameed



JC Joshua Cauble December 9, 2013 11:34 PM UTC

This sample was perfect!  I figured that event might have something to do with that but was getting lost on the other functions.  Thanks for the help.


SH Shakul Hameed M Syncfusion Team December 10, 2013 12:03 PM UTC

Hi Joshua,

 

Thanks for your update.

Please let us know if you require further assistance from us.

 

Thanks,

Shakul Hameed


Loader.
Live Chat Icon For mobile
Up arrow icon