Programmatically scrolling to last column in empty gridview

4 posts, 1 answers
  1. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 28 Jun 2011 Link to this post

    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?
  2. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Jun 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 30 Jun 2011 Link to this post

    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!


  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Jun 2011 Link to this post

    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
Back to Top