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

Programmatically scrolling to last column in empty gridview

3 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
haagel
Top achievements
Rank 1
haagel asked on 28 Jun 2011, 08:34 AM
I need to scroll to the last column (right-most) when I open a form with a RadGridView.

I use this code to scroll:
MyGridView.ScrollIntoView(null, MyGridView.Columns[MyGridView.Columns.Count - 1]);

This works, but only when there is data in the gridview. When I try to run this line of code before the gridview has any data, nothing happens. Am I doing something wrong, or is this just not possible?

3 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 29 Jun 2011, 03:55 PM
Hello haagel,

Please try the following code :
GridViewScrollViewer scrollViewer = this.RadGridView1.ChildrenOfType<GridViewScrollViewer>().First();
            scrollViewer.ScrollToRightEnd();

* for this you will need to add an "using Telerik.Windows.Controls" .

All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
haagel
Top achievements
Rank 1
answered on 30 Jun 2011, 08:00 AM
I tried writing your code last in the constructor of the user control that has the grid, but when I ran the application I got an exception:
InvalidOperationException: Sequence contains no elements

I put the code in an event handler for the Loaded event of the user control instead, and now it works.

Thanks Pavel!


0
Milan
Telerik team
answered on 30 Jun 2011, 08:18 AM
Hi Haagel,

  You get this error because no GridViewScrollViewer can be found when you execute the code in the constructor. The reason for this is that all UI elements are created a bit later. Please use the Loaded event as a signal for determining when the UI structure is ready. 

Greetings,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
haagel
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
haagel
Top achievements
Rank 1
Milan
Telerik team
Share this question
or