ListControl ScrollToItem - how to center selected item in center of list

2 Answers 57 Views
General Discussions ListControl
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Toby asked on 12 May 2023, 09:32 AM | edited on 12 May 2023, 09:44 AM

Hi,

I have used RadListControl.ScrollToItem to bring a searched for item into view,thi sbrings it into view but either at top or bottom of the list. Is it possible to somehow center the selected item in the middle of the view so that I can obtain context based on surrounding items ?

Many thanks

Toby

2 Answers, 1 is accepted

Sort by
0
Accepted
Toby
Top achievements
Rank 3
Iron
Iron
Iron
answered on 12 May 2023, 10:38 AM

I believe I have answered my own question, so for others to want this ability, this was my solution. "list" is the RadListControl, "curIdx" is the index of the item you want centered in the view

list.SelectedIndex = curIdx;
list.ListElement.VScrollBar.Value = ( list.ItemHeight * list.SelectedIndex ) - ( list.Height / 2 ) + list.ItemHeight;
Hope that this helps others
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2023, 04:45 AM

Hi, Toby,

I am glad that you have found a suitable solution for your scenario. Indeed, setting the VScrollBar.Value property is an appropriate way to control to which item the view is navigated.

If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions ListControl
Asked by
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or