ListBox - how to make selected item the first item in the list


  • Hey all,

    selected item in my listbox must always be first item in the list. I was hoping to achieve this by putting ListBox into ScrollViewer and on ListBox.SelectionChanged send several ScrollViewer.LineDown(). In some cases this works, but if i select last item in the list, LineDown() does nothing because there is nowhere to scroll. Is there any way to override this, or perhaps i should use different approach?
    Thursday, September 06, 2007 8:33 AM

All replies

  • Bump
    Friday, September 07, 2007 6:21 AM
  • Your scenario is a little bit vague so depending on your reguirements this may or may not be helpful. You might try to move the selected Item to the top of the ListBox and then scroll the box to the top. If the ItemsCollection is databound you would have to manipulate the source collection of course... Not sure if moving the items around is acceptable in your scenario though...

    Friday, September 07, 2007 7:34 AM
  • This would work, but i kept this idea as a backup scenario. I'll try to clear up what i'm trying to do. I have a ListBox what holds some items. When item is selected it expands into full blown control that has Next/Prev buttons. Next/Prev buttons move list selection. Now if i press Next, ListBox selects next item and it becomes 'expanded' but the whole control is a bit lower so i have to move my mouse down to reach Next button again. So instead of trying to catch control each time i press next i would rather have it stay in one place. My idea was to user Scrolling somehow and make the selected item stay in one place.
    Friday, September 07, 2007 1:44 PM