.net Listview - changed before item selection

Does anyone know how to implement something like "before the selected event"?

I will explain what I need. There are elements in the list, and when you select an element, the text fields are filled in the form with a large amount of data on this element.

When I click on another item in the list, I want to ask if the changes should be saved before another item is selected (visually). The save option has 3 options, yes no and cancels, when you cancel the current item you need to remain selected. I did the same with datagrid, inheriting and overriding OnMouseDown and OnKeyDown, but I really don't see a solution for the list.

+3
source share
1 answer

, OnSelectedIndexChanged. - ( ), .

:

private int PrevoiusSelectedIndex = -1;

public void MyListBox_SelectedIndexChanged(object sender, EventArgs e){
    if (PrevoiusSelectedIndex != -1){
         // show message box
         // save all the data for item at index PrevoiusSelectedIndex 
    }
    PrevoiusSelectedIndex = ((ListBox)(sender)).SelectedIndex;
}
+1

All Articles