RadListBox AutoScroll and ScrollIntoView not working

6 posts, 0 answers
  1. shovavnik
    shovavnik avatar
    39 posts
    Member since:
    Aug 2007

    Posted 27 Oct 2007 Link to this post

    I've added a RadListBox to a form and I add items to the list box at runtime. I'd like the listbox to scroll to show the newest item when it's added.

    I tried 2 methods, and neither works:

    1.. I've set the AutoScroll to True in the designer.
    2. I've implemented the ControlAdded event as follows:

                MyList.ScrollControlIntoView(e.Control);

    I've tried them together too.

    Any ideas?

    By the way, scrolling them into view should not move the focus to the listbox.

    Thanks...

  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 29 Oct 2007 Link to this post

    Hello shovavnik,

    The second scrolling approach you've described is close to the functionality you're trying to implement. However, calling the ScrollControlIntoView method would do nothing, since the items in the listbox are not controls.

    To achieve your goal, you should call the RadListBoxElement.ScrollElementIntoView method instead, passing the item as a parameter in the way illustrated below:

    RadListBoxElement element = (RadListBoxElement)radListBox1.RootElement.Children[0];  
    element.ScrollElementIntoView(radListBox1.Items[radListBox1.Items.Count - 1]);  
     

    This code will always scroll to the last item in the Items collection.

    I hope this helps. Contact us again, if you have other questions.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Simon Cross
    Simon Cross avatar
    2 posts
    Member since:
    Nov 2007

    Posted 12 Dec 2007 Link to this post

    Yeah right! In your dreams this will auto-scroll to the item - this doesn't work...
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 13 Dec 2007 Link to this post

    Actually, Simon, this code does work. We have attached an application which demonstrates the approach - please, review it and let us know how it works for you. 

    Note that you should scroll to an item in the Form_Shown event handler, since this is the first event fired after RadListBox layout has been calculated. At any earlier moment than this, scroll position will be calculated incorrectly, therefore it may seem as RadListBox does not scroll at all.

    In case you still experience problems, please let us know exactly what does not work so that we can help you.
     

    All the best,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Simon Cross
    Simon Cross avatar
    2 posts
    Member since:
    Nov 2007

    Posted 13 Dec 2007 Link to this post

    Ok, now it works, thanks for that Nikolay.

    It's not really that obvious though, there's nothing in the documentation
    on this method stating the importance of when in the life cycle of a form
    it should be called.


  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 14 Dec 2007 Link to this post

    Hi Simon Cross,

    Thank you for the feedback.

    We are planning to refactor the layout of RadListBox in one of our upcoming releases and then the documentation will be updated according to the new specifics.

    Thank you again for the feedback. Please do not hesitate to contact us if you have other questions.

    Greetings,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready