c# - programmatically select next listbox item -
I am trying to program two buttons to mimic up / down arrow key behavior, which means that When I press the button up, it takes up an item in my list box and so on. I have written the following code:
Private zero mainlistup (object sender, System.Windows.RoutedEventArgs e) {if (ListBox_Copy.SelectedIndex = -1 & amp; listBox_Copy.SelectedIndex & LT ; ListBox_Copy! .ems.Count & amp; amp; listBox_Copy.SelectedIndex = 1) {listBox_Copy.SelectedIndex = listBox_Copy.SelectedIndex - 1; }} Private Zero Mainlistdown (Object Sender, System.Windows.RoutedEventArgs e) {if (ListBox_Copy.SelectedIndex & lt; listBox_Copy.Items.Count & ListBox_Copy.SelectedIndex = -1) {listBox_Copy.SelectedIndex = listBox_Copy .SelectedIndex + 1; }}
This works, however, the item has lost its selection when pressing the button ... the selection index is set correctly (other data-bound items, binded in the selected item But the list box item is no longer highlighted. How do I set selected items to be highlighted?
After the text "itemprop =" text ">
GenericTypeTea says, it is likely that it seems to do with the lost focus one more The issue is that your code is incomplete and will not let you go to the item at the top. I'd like to suggest something to change it:
move up
if (listBox_Copy.SelectedIndex> 0) {listBox_Copy.SelectedIndex = listBox_Copy .SelectedIndex - 1; }
move down
if (listBox_Copy.SelectedIndex & lt; listBox_Copy.Items.Count - 1) {listBox_Copy.SelectedIndex = listBox_Copy.SelectedIndex + 1; }
Comments
Post a Comment