tags:

views:

88

answers:

1

I have A ListView and and delete button on a 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

+2  A: 

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;
Jhonny D. Cano -Leftware-
Thanks Jhonny that Helped
Gaddigesh
glad to help... Please, acccept the answer if it has helped you
Jhonny D. Cano -Leftware-
To accept, you can click the check mark at the left side of the answer
Jhonny D. Cano -Leftware-