Bring the selected Item into View

14 posts, 2 answers
  1. Nils
    Nils avatar
    46 posts
    Member since:
    Jul 2009

    Posted 18 Jan 2010 Link to this post

    Hi.
    I Have a RadGridView with a vertical scrollbar.
    Is there a possibility to bring a certain Item into view.
    I have tried Selected and Current however, the scrollbar remains unchanged.
    Ideally I need something like:
    var newItemInMyList = GetNewItem();  
    this.ItemsSource.Add(newItemInMyList);  
    this.SelectedItem = newItemInMyList;  
    this.CurrentItem = newItemInMyList;  
    this.radGridView1.BringIntoView(newItemInMyList);  

    However if that is not possibile I would settle with bringing the scrollbar to the bottom of the Grid. (For the new Item woll most likely be added at the end of the list...)

    Yours,
    Nils


  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Jan 2010 Link to this post

    Hi Nils,

    Can you post more info about your grid version?

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 18 Jan 2010 Link to this post

    Hello Nils,

    You can use the ScrollIntoView method of RadGridView. For example:

    var newItemInMyList = GetNewItem();  
    this.ItemsSource.Add(newItemInMyList);  
    this.SelectedItem = newItemInMyList;  
    this.CurrentItem = newItemInMyList;  
    this.radGridView1.ScrollIntoView(newItemInMyList);


    All the best,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Nils
    Nils avatar
    46 posts
    Member since:
    Jul 2009

    Posted 18 Jan 2010 Link to this post

    @Vlad: I am still using 2009.2.813.35
    @Milan: (Now..) I found that there was a fix to this function in 2009.3.1208, but I can't seem to find when this was added. And It's not there in 2009.2.813...

    Any Ideas on how to mimic this behaviour in 2009.2.813 ??

    Nils
  6. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 19 Jan 2010 Link to this post

    Hello Nils,

    There is a similar method in Q2 called BringDataItemIntoView that you can use.

    this.radGridView1.BringDataItemIntoView(newItemInMyList);


    All the best,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Nils
    Nils avatar
    46 posts
    Member since:
    Jul 2009

    Posted 19 Jan 2010 Link to this post

    Boy, I was so close...
    I looked and looked, but I never acually typed "bring..."

    Thanks for the help.

    Nils
  8. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2014

    Posted 06 Jan 2015 in reply to Milan Link to this post

    None of this works for me...
    var newItemInMyList = GetNewItem();  
    this.ItemsSource.Add(newItemInMyList);  
    this.SelectedItem = newItemInMyList;  
    this.CurrentItem = newItemInMyList;  
    this.radGridView1.ScrollIntoView(newItemInMyList);

    GridView.SelectedItem and GridView.CurrentItem do not get set upon the above assignment. What should the states of EnableLostFocusSelectedState="False" IsSynchronizedWithCurrentItem="false" be set to? Can some please post a project that shows this working for items scrolled out of view??? Thank you
  9. Boris
    Admin
    Boris avatar
    276 posts

    Posted 07 Jan 2015 Link to this post

    Hello Richard,

    For a more practical example on how to Scroll to a particular row or column, you can check the ScrollIntoViewAsyncMvvm sdk example. In addition you can read more about the mentioned above properties in the Stop Showing the Unfocused State and CurrentItem vs SelectedItem documentation articles.

    I hope this helps.

    Regards,
    Boris
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2014

    Posted 07 Jan 2015 in reply to Boris Link to this post

    Is this some kind of paging issue going on with the RadGridView? 
  11. Boris
    Admin
    Boris avatar
    276 posts

    Posted 08 Jan 2015 Link to this post

    Hello Richard,

    Could you please provide us with more information about your case, perhaps a small runnable project that reproduces the issue ? By providing us with such a project we will be able to debug it on our side and inform you of our findings. In addition, if you are not entirely sure how to isolate it, you can check this Isolating a problem in a sample project  blog post for some guidance.

    We are looking forward to your reply.

    Regards,
    Boris
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2014

    Posted 08 Jan 2015 in reply to Boris Link to this post

    My small project doesn't reproduce the problem.

    My suspect is the SelectedItem="{Binding SelectedProperty}" line of xaml:

    <telerik:RadGridView x:Name="gvProperties" Grid.Row="1"
    ItemsSource="{Binding DataContext.Properties, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadRibbonWindow}}"
    SelectedItem="{Binding SelectedProperty}" <<<<<<<<<<<<<< this line right here <<<<<<<<<<<<<<

    I highly suspect that the RadGridView.SelectedItem is being overwritten by the telerik library due to this binding. All my other RadGridViews do not have this problem and do not use SelectedItem binding. Is this a known issue? how do I reset the selected item after sorting? RadGridView.SelectedItem is overwritten AFTER the SortED routine exits.
  13. Boris
    Admin
    Boris avatar
    276 posts

    Posted 13 Jan 2015 Link to this post

    Hi,

    In order to avoid double posting, I would like to kindly ask you to keep any further communication regarding this issue in your support ticket.


    Regards,
    Boris
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  14. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2014

    Posted 13 Jan 2015 in reply to Boris Link to this post

    I haven't posted here in 5 days. My resolution was posted to the support ticket, but your users might like to know the resolution we came to. We were querying the data database as IQueriable. As an Iqueriable the Selected item was being changed to null and then to the new index of the reordered items. (This caused the OnPropertyChanged method to be fired twice.) By casting the results of the query to IEnumerable using .ToList() (or alternately "As Enumerable") the "SelectedItem" in the Rad Grid view stays intact.

    This is directly related to the problem of scrolling into view. The control would scroll to the "index" of the reordered/requeried list of items, but the previously selected item was moved off the screen. Now... We are not done. The ScrollintoView and ScrollIntoViewAsync still did not work (I would say that is a bug.) - (And BringIndexIntoView only brings something into the view at the top or bottom). We wanted the selected item to always appear at the top of the current view. We required a custom method to find the index of the selected item and use BringIndexIntoView. I will post that code below:

            public static void FindItemInTheList(this RadGridView grid, object item)
            {
                grid.BringIndexIntoView(grid.Items.IndexOf(item));

                GridViewRow targetRow = grid.ChildrenOfType<GridViewRow>().Where(r => r.Item == item).FirstOrDefault();
                var scrollViewer = Util.GetScrollViewer(grid) as ScrollViewer;

                //scroll the selected item up until it is not visible
                double lastVerticaleOffset = -1;
                while (targetRow != null && targetRow.IsVisible && scrollViewer.CanContentScroll && scrollViewer.VerticalOffset != lastVerticaleOffset)
                {
                    lastVerticaleOffset = scrollViewer.VerticalOffset;
                    scrollViewer.LineDown();
                    grid.UpdateLayout();
                }

                //scroll the row back into view
                grid.BringIndexIntoView(grid.Items.IndexOf(item));
            }
  15. Boris
    Admin
    Boris avatar
    276 posts

    Posted 15 Jan 2015 Link to this post

    Hi Richard,

    Thank you for sharing your resolution with our community.

    Regards,
    Boris
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready