Selected item to top of ListBox

Discussion in 'Questions (Windows Mobile)' started by HARRY, Dec 15, 2008.

  1. HARRY

    HARRY Active Member Licensed User

    Hi,

    In a program I have a ListBox with many items. I want to help the user in scrolling as I know roughly which item he will need. I managed to select programmatically that item. It appears at the bottom of the ListBox. Does somebody know a possibility to get programmatically that selected item on the top of the list?

    Harry
     
  2. taximania

    taximania Well-Known Member Licensed User

    Can't you use the index and a temp variable to swap the two.

    Sorry for the short reply. I didn't have time to test what I said :sign0137:
     
  3. Cableguy

    Cableguy Expert Licensed User

    That's a thought one...
    If you DO know what the probable choice is, then delete the item from the list box, and then add ity again to the first position....
    listbox.additem(0)="myItem"
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    As Cableguy wrote you should remove the item with ListBox.Remove or ListBox.RemoveAt and then add it with ListBox.Insert(0,"some value").
     
  5. HARRY

    HARRY Active Member Licensed User

    Hi,

    Thanks for your suggestions. However, as the list is in alphabetic sequence, I cannot move items to another place. I found myself the following solution:

    Find the index of the probable candidate
    Add to it the number of visible items -1
    Check on the Count and correct if necessary
    Select the raised index
    Select the original index

    Using Visible is false and true around this operation gives an acceptable performance (as it does with various Table operations).

    Harry
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice