469,588 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

Cancelling the ListView SelectedIndexChanged event

I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message box that warns that their changes will be lost, and asks them to confirm whether to continue. Sounds simple

Unfortunately, the ListView's SelectedIndexChanged event cannot be cancelled, and it's actually called for each change in the selection. So, for example, if item 1 is selected and the user then selects item 2, the event is called twice: once to remove the selection of item 1, and then to add the selection of item 2. If you go from having one item selected to having five (for example), the event fires to remove your original selection, and then again for each of your new selections - six hits in all

Obviously, this makes it a pain to determine when the event should be cancelled and reset back to the original. I obviously don't want my message box appearing six times....

Does anyone have a workaround for this

Thanks..
Nov 22 '05 #1
8 6019
Hi Invisible

The selectionIndexChange event is the default however it is not said that
you should use it.
There is also the click event, the columnclick, mouseup, why not try one of
those.

I hope this helps?

Cor
Nov 22 '05 #2
Hi Invisible

The selectionIndexChange event is the default however it is not said that
you should use it.
There is also the click event, the columnclick, mouseup, why not try one of
those.

I hope this helps?

Cor
Nov 22 '05 #3
Hi Invisible,

I forgot, for this kind of questions are also newsgroups as
microsoft.public.dotnet.languages.vb and csharp (also for C++ and J#)

There are also special control newsgroups, however to that you can add as
crosspost, but they are in my opinion as dead as a newsgroup dead can be.

Cor
Nov 22 '05 #4
Hi Invisible,

I forgot, for this kind of questions are also newsgroups as
microsoft.public.dotnet.languages.vb and csharp (also for C++ and J#)

There are also special control newsgroups, however to that you can add as
crosspost, but they are in my opinion as dead as a newsgroup dead can be.

Cor
Nov 22 '05 #5
Thanks for the help, Cor. Unfortunately, those events don't trap movements using the arrow keys, so I'd need to repeat everything in the KeyUp event too. It's worth considering, though

I'll try posting on that other group you mentioned; see if anyone there has any other idea

Duncan
Nov 22 '05 #6
Thanks for the help, Cor. Unfortunately, those events don't trap movements using the arrow keys, so I'd need to repeat everything in the KeyUp event too. It's worth considering, though

I'll try posting on that other group you mentioned; see if anyone there has any other idea

Duncan
Nov 22 '05 #7
Hi Invisible,

You can flag when data is changed. Display the message in
SelectedIndexChanged event only if this flag is true. After returning from
the message box, if you are not cancelling the event, set this flag to
false. Thus for subsequent firings of this event since this flag is false,
you will not be displaying the message box.

ThanQ...

"InvisibleDuncan" <an*******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new
item without saving, I want to display a message box that warns that their
changes will be lost, and asks them to confirm whether to continue. Sounds
simple.
Unfortunately, the ListView's SelectedIndexChanged event cannot be cancelled, and it's actually called for each change in the selection. So,
for example, if item 1 is selected and the user then selects item 2, the
event is called twice: once to remove the selection of item 1, and then to
add the selection of item 2. If you go from having one item selected to
having five (for example), the event fires to remove your original
selection, and then again for each of your new selections - six hits in all.
Obviously, this makes it a pain to determine when the event should be cancelled and reset back to the original. I obviously don't want my message
box appearing six times....
Does anyone have a workaround for this?

Thanks...

Nov 22 '05 #8
Hi Invisible,

You can flag when data is changed. Display the message in
SelectedIndexChanged event only if this flag is true. After returning from
the message box, if you are not cancelling the event, set this flag to
false. Thus for subsequent firings of this event since this flag is false,
you will not be displaying the message box.

ThanQ...

"InvisibleDuncan" <an*******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new
item without saving, I want to display a message box that warns that their
changes will be lost, and asks them to confirm whether to continue. Sounds
simple.
Unfortunately, the ListView's SelectedIndexChanged event cannot be cancelled, and it's actually called for each change in the selection. So,
for example, if item 1 is selected and the user then selects item 2, the
event is called twice: once to remove the selection of item 1, and then to
add the selection of item 2. If you go from having one item selected to
having five (for example), the event fires to remove your original
selection, and then again for each of your new selections - six hits in all.
Obviously, this makes it a pain to determine when the event should be cancelled and reset back to the original. I obviously don't want my message
box appearing six times....
Does anyone have a workaround for this?

Thanks...

Nov 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by InvisibleDuncan | last post: by
3 posts views Thread by sandman | last post: by
6 posts views Thread by tbrown | last post: by
12 posts views Thread by Tom Bean | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.