473,385 Members | 1,769 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,385 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 20 '05 #1
2 1943
Hi Invisible,

I made something, I think from this you should have to be able to make it
yourself?

Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.MultiSelect = False
ListView1.Items(0).Selected = True
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal _
sender As System.Object, ByVal e As System.EventArgs) _
Handles ListView1.SelectedIndexChanged
Static previous As Integer
If ListView1.SelectedItems.Count > 0 Then
Dim this As Integer = _
DirectCast(ListView1.SelectedItems(0), ListViewItem).Index
If this <> previous Then
MessageBox.Show("I am selected on row " & (this +
1).ToString)
End If
End If
End Sub
///
Nov 20 '05 #2
Cor,

That looks very promising - I'll have a go with it and see what I can come up with.

Thanks for taking the time.

--
Duncan
Nov 20 '05 #3

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; ...
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...
13
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration...
10
by: HABJAN ®iga | last post by:
Ok, the trouble: On form: Mask (lots of textboxes & ...) Listview 1 as Listview with some items booEdit as boolean=False intEditIndex as integer Scenario:
6
by: George | last post by:
Hi all, How can I get the value stored from the selected item and subitems of a listview? Thanks in advance, George
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
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,...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.