472,368 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

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 2889
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vince | last post by:
I need to programmatically select the first item in a listview before the listview is displayed, so far I'm not having any luck. Here's what I tried in the init for the listview... ...
1
by: Sean Chapman | last post by:
I was wondering how I would go about programmincally selecting a listView item in a listView since the Selected val is read-only. I can't seem to find any other method that will do this for me. I'm...
1
by: Bob Geltz | last post by:
I am able to populate a ListView with several detail lines (several columns). When finished, I would like to pre-select the first item in the list (before the user interacts with the list). This...
4
by: Paddy | last post by:
How do I select a subitem from a listview after clicking on the first column? Couldn't find it in MSDN. Thank you. Paddy.
2
by: Fritz | last post by:
I know it, I know it. It's come up a lot. I've done the Googling, but the standard answer doesn't do what I expect it to. For the record, the standard answer is: "Set the Selected property of a...
3
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate...
0
by: Benny Raymond | last post by:
I have a list view and a button that turns the currently selected item's ForeColor to SystemColors.GrayText The problem I'm having is that when the user clicks in white space, the item becomes...
5
by: Bart Steur | last post by:
Hi, What's the best way to programmaticly select (click) another listview Item after removing the selected/focused one. using VB2005 Express. Thanks Bart
1
by: c35tar1 | last post by:
I have a ListView within a dialog. In code the groups are created and items added. Display is 100% correct. The problem is with using Shift to select multiple items in the list. - If you...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.