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
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.
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.
@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
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.
I looked and looked, but I never acually typed "bring..."
Thanks for the help.
Nils
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
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.
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.
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.
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.
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));
}
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.