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

Bring the selected Item into View

13 Answers 783 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nils
Top achievements
Rank 1
Nils asked on 18 Jan 2010, 10:48 AM
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


13 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 Jan 2010, 11:24 AM
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.
0
Accepted
Milan
Telerik team
answered on 18 Jan 2010, 11:27 AM
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.
0
Nils
Top achievements
Rank 1
answered on 18 Jan 2010, 02:34 PM
@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
0
Accepted
Milan
Telerik team
answered on 19 Jan 2010, 10:53 AM
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.
0
Nils
Top achievements
Rank 1
answered on 19 Jan 2010, 11:45 AM
Boy, I was so close...
I looked and looked, but I never acually typed "bring..."

Thanks for the help.

Nils
0
Richard
Top achievements
Rank 1
answered on 06 Jan 2015, 03:12 PM
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
0
Boris
Telerik team
answered on 07 Jan 2015, 05:23 PM
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.

 
0
Richard
Top achievements
Rank 1
answered on 07 Jan 2015, 06:21 PM
Is this some kind of paging issue going on with the RadGridView? 
0
Boris
Telerik team
answered on 08 Jan 2015, 05:35 PM
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.

 
0
Richard
Top achievements
Rank 1
answered on 08 Jan 2015, 08:04 PM
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.
0
Boris
Telerik team
answered on 13 Jan 2015, 03:17 PM
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.

 
0
Richard
Top achievements
Rank 1
answered on 13 Jan 2015, 03:45 PM
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));
        }
0
Boris
Telerik team
answered on 15 Jan 2015, 11:45 AM
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.

 
Tags
GridView
Asked by
Nils
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Milan
Telerik team
Nils
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Boris
Telerik team
Share this question
or