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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid - AutoScroll and AutoEdit

Thread ID:

Created:

Updated:

Platform:

Replies:

126283 Oct 5,2016 03:02 PM UTC Oct 10,2016 12:13 PM UTC WPF 3
loading
Tags: SfDataGrid
Kurt Zimmermann
Asked On October 5, 2016 03:02 PM UTC

Hi,

I am trying to do the following:
  • I have a SfDataGrid bound to a ObservableCollection<>
  • When the user clicks a button outside of the SfDataGrid I append a new item at the end of the Collection
  • The SfDataGrid should scroll automaticaly to the last row (representing the added item)
  • The SfDataGrid should start EditMode for this row

I have got the Scrolling to work by using the DataContextChanged event and the CollectionChanged event - but this is a very complex and ugly Code for such a simple Problem.

Do you have a nice solution for this?


Thanks Kurt


Sowndaiyan Paulpandi [Syncfusion]
Replied On October 6, 2016 12:51 PM UTC


Hi Kurt,

Thanks for contacting Syncfusion Support.

In SfDataGrid, you can achieve your requirement “AutoScroll and AutoEdit while adding new item in collection’ by using the ScrollToEnd method and BeginEdit method like the below code example,

C#
 
private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            (this.DataContext as ViewModel).OrdersDetails.Add(new OrderInfo() { CustomerID = "100009", Freight = 100 }); 
 
            this.dataGrid.GetVisualContainer().ScrollOwner.ScrollToEnd(); 
 
            Dispatcher.Invoke(new Action(() => 
            { 
                var viewModel = this.dataGrid.DataContext as ViewModel; 
                //find the RowIndex for particular record 
                var RowIndex = this.dataGrid.ResolveToRowIndex(viewModel.OrdersDetails[viewModel.OrdersDetails.Count - 1]); 
                // CurrentCell is set if MappingName is EmployeeID 
                this.dataGrid.MoveCurrentCell(new RowColumnIndex(RowIndex, 0)); 
                this.dataGrid.SelectionController.CurrentCellManager.BeginEdit(); 
            }),System.Windows.Threading.DispatcherPriority.ApplicationIdle); 
          
        } 

We have prepared a sample as per your requirement and you can download the sample from the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/126283/ze/WPF-1761942878
 

Regards,
Sowndaiyan
 


Kurt Zimmermann
Replied On October 7, 2016 12:57 PM UTC

Hi,

thank's very much. I implemented it the way you suggest and it works perfect. The only differnece, I put your code in the CollectionChanged event of the Collection:

model.Medications.CollectionChanged += (s, e1) =>

{

if (e1.Action == NotifyCollectionChangedAction.Add)

{

this.DataGrid.GetVisualContainer().ScrollOwner.ScrollToEnd();

...


Regards

Kurt

Farjana Parveen Ayubb [Syncfusion]
Replied On October 10, 2016 12:13 PM UTC

Hi Kurt, 
 
Thank you for your response. 
 
Please let us know if you require further assistance from us. 
 
Regards, 
Farjana Parveen A 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;