473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

Similar topics

8
by: InvisibleDuncan | last post by:
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...
0
by: LV | last post by:
Hello, When I manually set a list view item to be a selected item, the SelectedIndexChanged event is not firing. Am I missing something here? using System; using System.Windows.Forms; ...
3
by: sandman | last post by:
I've got a combo box that has an event handler set for SelectedIndexChanged event. The problem is that it's firing at startup when I load data from the Form_OnLoad event. I tried setting a flag...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
0
by: BillCo | last post by:
I'm a C# Newbie, so if I've missed the obvious here go easy!!! I have a form opened from a MDI parent. The form has a data bound combo box, with a SelectedIndexChanged event (fills a list view...
2
by: ArunDhaJ | last post by:
Hi Friends, I'm using .Net1.1. The SelectedIndexChanged event is generated twice when i change the selection. I think this is because the event is triggered when an item loses focus and the...
2
by: David Jackson | last post by:
Hello, I'm using VS.NET 2005. I have a ListView populated with data pulled from a SQL Server database. I have wired up a SelectedIndexChanged event, but I can't find any way of retrieving...
12
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.