locked
ListBox: Selecting items by keyboard don't respect actual SelectedItem/SelectedIndex RRS feed

  • Question

  • Here is my situation:

     

    I have a ListBox populated with items and I have attached an eventhandler to the SelectionChanged event. In the eventhandler I use my own logic to determine whether I actually want the user to select that item at this time (based on the state of the item and a few other business specific details). If this item is determined to be 'unselectable' at this time, I set the SelectedItem property of the listbox back to the previously selected item through procedural code. The functionality is what I wanted, but with one small quirk.

     

    When clicking on the ListBox and giving it focus, then using the up and down arrow on the keyboard to change the selected item the actual position of the 'selector' in respect to the up and down arrow keys will ignore the actual selectedIndex and will move off onto the items it shouldn't regardless of me setting the actual value in code. It still functions the way I want it to in that the selected item is in fact the selected item that I told it to have, but the actual selector will think its off on other items that it shouldnt be, requiring me to press the up arrow 2 times to get back to the item i was just on instead of just once like you would think.

     

    Hopefully that makes sense. I guess my question is whether this is a bug with the keyboard focused up and down arrow selection not actually being in sync with the selectedItem or selectedIndex of the ListBox.

     

    Thanks,

    Bob Pace

    Software Developer

    Wednesday, July 11, 2007 4:35 PM

All replies

  • Hi Bob,

    You might have been turned into CEO of some company by now.But if you haven't , would you mind telling me , how did you get through this issue ?

    Thanks,

    BR,

    JollyWagoner

    Wednesday, May 2, 2012 6:28 PM