G
Guest
I have a form with a listview to allow users to select an item. When they
select one I fill in controls below it for them to modify the values. They
can also just enter new values in the controls without selecting a listview
item in order to insert new records. After entering new data if they select
a row in the listview I prompt them to make sure they want to save the
changes. If they select 'Cancel' I want to not highlight the newly selected
row and leave the data in the detail controls as it was. Otherwise the new
row is selected and the listview item is used to populate the detail
controls.
The problem seems to be that when I clear the selected items for the
listview the selectedindexchanged event fires again. I get the yesnocancel
prompt twice. If I step through the code in the debugger I only get it once.
I tried using a bool to skip the handler when clearing the selection but it
seems like the highlighting of the selected row then sometimes happens after
the clearing so it ends up in the selected anyway. I tried playing with the
clicked event and others and the events don't seem to always happen in a
predictable order. Each thing I try seems to create new issues and it seems
this shouldn't be this difficult. I've done similar things with the datagrid
but would like to use listview.
Basically want to be able to prompt the user sometimes when they select a
new listview item and if they "cancel" I want to be able to clear the
selection or set the selected item to a prior selected item without prompting
them a second time.
Any help would be appreciated. Thanks in advance.
Jeff
select one I fill in controls below it for them to modify the values. They
can also just enter new values in the controls without selecting a listview
item in order to insert new records. After entering new data if they select
a row in the listview I prompt them to make sure they want to save the
changes. If they select 'Cancel' I want to not highlight the newly selected
row and leave the data in the detail controls as it was. Otherwise the new
row is selected and the listview item is used to populate the detail
controls.
The problem seems to be that when I clear the selected items for the
listview the selectedindexchanged event fires again. I get the yesnocancel
prompt twice. If I step through the code in the debugger I only get it once.
I tried using a bool to skip the handler when clearing the selection but it
seems like the highlighting of the selected row then sometimes happens after
the clearing so it ends up in the selected anyway. I tried playing with the
clicked event and others and the events don't seem to always happen in a
predictable order. Each thing I try seems to create new issues and it seems
this shouldn't be this difficult. I've done similar things with the datagrid
but would like to use listview.
Basically want to be able to prompt the user sometimes when they select a
new listview item and if they "cancel" I want to be able to clear the
selection or set the selected item to a prior selected item without prompting
them a second time.
Any help would be appreciated. Thanks in advance.
Jeff