开发者

.net Listview - before item selection changed

开发者 https://www.devze.com 2023-02-17 02:17 出处:网络
anybody know how to implement something like a before \"item selected event\"? I\'ll explain what I need.

anybody know how to implement something like a before "item selected event"?

I'll explain what I need. There are items in a listbox, and with selecting an item, textboxes are filled on the form with more data on that item.

When clicking another item in the listbox I want to ask if the changes has to be saved, before the other item is (visually) selected. The save 开发者_开发问答option has 3 options, yes no and cancel, on cancel the current item needs to stay selected. I've done the same with a datagrid by inheriting and overriding OnMouseDown and OnKeyDown, but I don't really see a solution for the listview.


I think You should just implement all the functionality in the OnSelectedIndexChanged event. What would you need is a global variable (or class member) that holds the previous index state.

That is:

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消