469,928 Members | 1,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Canceling selecting a different item in a ListView

I'm working on a Windows app that has a ListView containing a bunch of items.
When the user clicks on an item, the app displays the item'd details. The
user then has the opportunity to edit these details. The user should click
the Save button after each change, but of course that doesn't always happen.

If the user makes changes and doesn't click Save, the app displays a message
box asking if they'd like to save their changes. This box includes a Cancel
button, and if they click Cancel, I'd like to short-circuit the selection of
the other item and keep the user at the one they were editing.

I can't find a way to do this. I've tried trapping the Click event, then the
MouseDown event and the Validating event and none of them seem to give me a
way to prevent the ListView from selecting the new item. I tried
programmitcally unassigning the handler for the SelectedIndexChanged event,
but that just prevents the details for the new item from showing up - the
ListView still selects the new item.

What do I need to do? Thanks.
Nov 17 '05 #1
2 2816
I think you can iterate through the ListView items and set/unset which are
selected:

listview.Items[10].Selected = false;

Here is how the technique is explained in detail:

http://msdn.microsoft.com/library/de...ectedtopic.asp

Alex

"David Anderson" <da*******************@tamko.com> wrote in message
news:76**********************************@microsof t.com...
I'm working on a Windows app that has a ListView containing a bunch of
items.
When the user clicks on an item, the app displays the item'd details. The
user then has the opportunity to edit these details. The user should click
the Save button after each change, but of course that doesn't always
happen.

If the user makes changes and doesn't click Save, the app displays a
message
box asking if they'd like to save their changes. This box includes a
Cancel
button, and if they click Cancel, I'd like to short-circuit the selection
of
the other item and keep the user at the one they were editing.

I can't find a way to do this. I've tried trapping the Click event, then
the
MouseDown event and the Validating event and none of them seem to give me
a
way to prevent the ListView from selecting the new item. I tried
programmitcally unassigning the handler for the SelectedIndexChanged
event,
but that just prevents the details for the new item from showing up - the
ListView still selects the new item.

What do I need to do? Thanks.

Nov 17 '05 #2
Okay, I see how that would restore the previous item, if I keep track of it.
Seems messy, but workable. I'll play with it.

Thanks.

"Alex Passos" wrote:
I think you can iterate through the ListView items and set/unset which are
selected:

listview.Items[10].Selected = false;

Here is how the technique is explained in detail:

http://msdn.microsoft.com/library/de...ectedtopic.asp

Alex

"David Anderson" <da*******************@tamko.com> wrote in message
news:76**********************************@microsof t.com...
I'm working on a Windows app that has a ListView containing a bunch of
items.
When the user clicks on an item, the app displays the item'd details. The
user then has the opportunity to edit these details. The user should click
the Save button after each change, but of course that doesn't always
happen.

If the user makes changes and doesn't click Save, the app displays a
message
box asking if they'd like to save their changes. This box includes a
Cancel
button, and if they click Cancel, I'd like to short-circuit the selection
of
the other item and keep the user at the one they were editing.

I can't find a way to do this. I've tried trapping the Click event, then
the
MouseDown event and the Validating event and none of them seem to give me
a
way to prevent the ListView from selecting the new item. I tried
programmitcally unassigning the handler for the SelectedIndexChanged
event,
but that just prevents the details for the new item from showing up - the
ListView still selects the new item.

What do I need to do? Thanks.


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sean Chapman | last post: by
1 post views Thread by Bob Geltz | last post: by
4 posts views Thread by Paddy | last post: by
3 posts views Thread by larry mckay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.