c# ListView item selection issue
I have A ListView and and delete button on 开发者_如何学Pythona Form
I can select any item and press delete button to remove the item (I have disabled Multiselect)
Requirement: As I delete an item next item should be selected if Bottom item is deleted then it should select previous item
How do i achieve it
maybe you can achieve it with the SelectedIndices collection:
if (lviList.SelectedIndices.Count == 0) return;
var ind = lviList.SelectedIndices[0];
int nextIndex;
if (ind == lviList.Count) {
nextIndex = ind - 1;
} else {
// when you remove, current index will be next item
nextIndex = ind;
}
DeleteItem(ind);
lviList.SelectedIndex = nextIndex;
精彩评论