Detect if scrollbar is visible

7 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 14 Dec 2012 Link to this post

    Hi!

    Is there anyway I can detect if a scrollbar in a GridView is visible or not if property is set to Auto?

    Regards
    Håkan
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Dec 2012 Link to this post

    Hello,

    Using the ChildrenOfType<> extension method , you can find the GridViewScrollViewer. Somtehing like : 

    this.RadGridView1.ChildrenOfType<GridViewScrollViewer>();

    All the best,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 14 Dec 2012 Link to this post

    Hi,

    I have done that already, but I can't seem to find any suitable property on it.

    I'm doing this when the collection in my view model changes.
    Tried to check if ExtentHeight is larger than ViewportHeight but sometimes it it larget even thought the scrollbar is not visible.
    That happens if you remove items until the scrollbar is hidden.

    Regards,
    Håkan
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Dec 2012 Link to this post

    Hello,

    The ScrollViewer has  viewport height and extent height .If the extent is larger than the viewport - > a scroll bar appears.

    Regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 17 Dec 2012 Link to this post

    Hi Pavel.

    I'm doing as you say, but it seems to be in the wrong place.
    I do the check in the CollectionChanged event.

    My grid fits 10 records so the scrollbar appears when adding the 11:th.
    But at that point the ExtentHeight is 260 and the ViewportHeight is 261, so it seems the 11:th record is not added to the grid at this point.

    If I remove the 11:th record, the ExtentHeight is 286, so that meend it's still in the grid at this point.

    Is there a better place to do the check, when the grid is actually updated after the CollectionChanged event?

    Regards,
    Håkan

  7. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Dec 2012 Link to this post

    Hello,

    You may try to perform the extent/viewport check in the LayoutUpdated event of RadGridView.

    Kind regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 18 Dec 2012 Link to this post

    That worked fine, thank you!

    - Håkan
Back to Top
DevCraft banner