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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Scroll the selected item into view

Thread ID:

Created:

Updated:

Platform:

Replies:

121515 Dec 22,2015 05:18 PM UTC Dec 24,2015 09:28 AM UTC WPF 3
loading
Tags: SfDataGrid
sabrina c.
Asked On December 22, 2015 05:18 PM UTC

Hi, I've found something on this subject but they are specific cases not simple as mine so I ask:

I have a grid where I programmatically add a record, the added record is then selected using the ViewModel Binding.

My Grid has:

ItemsSource = "{Binding MyElementsCollection}"
SelectedItem = "{Binding MySelectedItem}

When I set the selected item from code, It works perfectly except for the fact that if the selected item is not inside the visible part of the grid it remains invisible.

So, I wanted to know if there is a way to do something like:

MyDatagrid.SelectedItem.ScrollIntoView();

thank you in advance
Sabrina

Ayyanar Sasi Kumar Jeyaraj [Syncfusion]
Replied On December 23, 2015 12:38 PM UTC

Hi Sabrina,

You can achieve your requirement by using the ProcessSelectedItemChanged method in the GridSelectionController class.This method handles the selection and you can able to view the selected item in the Grid.

You can customize the GridSelectionController class and set the instance of that customized GridSelectionControllerExt class to datagrid.SelectionController property.
C#

this.datagrid.SelectionController = new GridSelectionControllerExt(datagrid); 


public class GridSelectionControllerExt : GridSelectionController

    {

        public GridSelectionControllerExt(SfDataGrid datagrid)

            : base(datagrid)

        {

        }

        protected override void ProcessSelectedItemChanged(SelectionPropertyChangedHandlerArgs handle)

        {

            base.ProcessSelectedItemChanged(handle);

            if (handle.NewValue != null)

                this.DataGrid.ScrollInView(this.CurrentCellManager.CurrentRowColumnIndex);

        }


    }


XAML

<Syncfusion:SfDataGrid x:Name="datagrid" 

                                       ColumnSizer="Star"

                                       AutoGenerateColumns="True"

                                       NavigationMode="Cell"

                                       AllowEditing="True"

                                       ItemsSource="{Binding OrderInfoCollection }"
                                       SelectedItem="{Binding MySelectedItem,Mode=TwoWay}">



Sample: http://www.syncfusion.com/downloads/support/forum/121515/ze/WPF431200764

Please let us know if you have any further assistance.

Regards
Ayyanar

sabrina c.
Replied On December 23, 2015 02:05 PM UTC

It Works perfectly, Thank You very much
Sabrina

Ashwini Paranthaman [Syncfusion]
Replied On December 24, 2015 09:28 AM UTC

Hi Sabrina,
Thank you for the update.
We are glad that your issue has been fixed.
Please let us know if you need any other assistance.
Regards,
Ashwini P.

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

;