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

Getting Virtical Scroll Event from RadGridView

2 Answers 890 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 11 Mar 2014, 02:35 PM
I am trying to find a way to get a scroll event from the RadGridView control.  Our requirements want us to display a WebBrowser Control within our row details of the RadGridView.  The issue with this is when the row scrolls up or down outside of the bounds of the grid the browser control remains and will overlay other controls outside of the grid which looks a little odd.  What I would like to do is register for a vertical scroll event so that I can collapse the expended row details to remove the browser control from the view.  Is there a way to get the scroll event.  I tried using ScrollViewerExtensions.GetAttachedVerticalScrollBar to acquire the scroll bar but always get null and I can't see any other way to get an event from the grid view itself.  Any assistance would be greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Mar 2014, 02:27 PM
Hello Eric,

If you want to handle ScrollChanged event of the grid, you can try finding the ScrollViewer and subscribe to its event. For example:
public MainWindow()
        {
            InitializeComponent();
 
            this.clubsGrid.Loaded += this.OnLoaded;
        }
 
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var scrollViewer = this.clubsGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
            if (scrollViewer != null)
            {
                scrollViewer.ScrollChanged += this.OnScrollChanged;
            }
        }
 
        private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
        {
             
        }


Will that approach meet your requirements ?

Regards,
Maya
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Lawrence
Top achievements
Rank 2
Iron
answered on 17 Jan 2017, 05:02 PM

I'm little late to the party, but I couldn't find a good example on how to do this.  Below, is what I came up with.  This is the code behind of your window.

        public Audit()
        {
            InitializeComponent();

            this.FoundationGridViewOldValues.Loaded += delegate { SetScrollBars(this.FoundationGridViewOldValues, this.FoundationGridViewNewValues); };
            this.FoundationGridViewNewValues.Loaded += delegate { SetScrollBars(this.FoundationGridViewNewValues, this.FoundationGridViewOldValues); };
        }

        private static void SetScrollBars(RadGridView source, RadGridView destination)
        {
            GridViewScrollViewer scrollViewerNew = source.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();

            if (scrollViewerNew != null)
            {
                scrollViewerNew.ScrollChanged += delegate (object sender, ScrollChangedEventArgs args)
                {
                    GridViewScrollViewer scrollViewerOld = destination.ChildrenOfType<GridViewScrollViewer>().First();

                    double horizontalOffset = args.HorizontalOffset;
                    double verticalOffset = args.VerticalOffset;

                    scrollViewerOld.ScrollToHorizontalOffset(horizontalOffset);
                    scrollViewerOld.ScrollToVerticalOffset(verticalOffset);
                };
            }
        }

Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Maya
Telerik team
Lawrence
Top achievements
Rank 2
Iron
Share this question
or