This question is locked. New answers and comments are not allowed.
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...
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
0
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:
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
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
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
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.
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
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
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