views:

152

answers:

1

Hi

I have a WPF listbox, with some custom item inside.

When user wants to deleta on of the item, what happens is that he has to reselect manually in the list rigth after delete because the list "seems" to lose focus OR no selected item exists.

Any idea ?

Thanks Jonathan

+1  A: 

We always handle this by setting the selected item in code. If it was the last item in the list, make the selected index the last item. Otherwise we make it the one after the one that was deleted.

if (SnippetsList.Items.Count > index) 
    SnippetsList.SelectedIndex = index;
else 
    SnippetsList.SelectedIndex = SnippetsList.Items.Count - 1;
Donnelle
thank you.However i think i have some issue implementing this. The reason is that i perform delete using pure XAML and i don't know where to use the code... (i use caliburn)