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

RadListBox AutoScroll and ScrollIntoView not working

5 Answers 618 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
shovavnik
Top achievements
Rank 1
shovavnik asked on 27 Oct 2007, 05:31 PM
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...

5 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 29 Oct 2007, 04:23 PM
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
0
Simon Cross
Top achievements
Rank 1
answered on 12 Dec 2007, 11:43 PM
Yeah right! In your dreams this will auto-scroll to the item - this doesn't work...
0
Nikolay
Telerik team
answered on 13 Dec 2007, 05:06 PM
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
0
Simon Cross
Top achievements
Rank 1
answered on 13 Dec 2007, 09:53 PM
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.


0
Nikolay
Telerik team
answered on 14 Dec 2007, 12:00 PM
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
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
shovavnik
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Simon Cross
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or