473,888 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListView SelectedIndexCh anged fires when e.Cancel set in Validatin

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 board.

I have a form that contains a ListView and a GroupBox control. The GroupBox
control itself contains several TextBox Controls. I have Validating and
Validated event handlers set for the GroupBox control, and a
SelectedIndexCh anged event handler for the ListView control.

The desired operation for this form is for the TextBox Controls contained
within the GroupBox to dynamically update their content when an item is
selected in the ListView control. This is handled via the
SelectedIndexCh anged event. When this event is fired the fields contained
within the GroupBox should update based on the selected ListViewItem.

Before a new item can be selected in the ListView control, the values
contained in the TextBox controls should be validated and stored before their
contents are updated by the SelectedIndexCh anged event. If validation fails
on any of the TextBox controls then e.Cancel should be set to true for the
CancelEventArgs of the GroupBox's Validating event. This should prevent the
ListViewControl SelectedIndexCh anged event from firing, and the record from
updating, as Cancel has been set to true for the GroupBox control's
Validating event.

The following code snippet examples the setup:

private void ListView_Select edIndexChanged( object sender, System.EventArg s e)
{
//Update GroupBox fields with currently selected record
this.updateGrou pBoxFields();
}

private void GroupBox_Valida ting(object sender,
System.Componen tModel.CancelEv entArgs e)
{
//Cancel the operation if field validation fails
e.Cancel = !this.checkForm Fields();
}

private void GroupBox_Valida ted(object sender, System.EventArg s e)
{
//Validation has succeeded, update the current record.
this.updateCurr entRecord();
}

private bool checkGroupBoxFi elds()
{
//The code here verifies the values in the fields and returns true if
they are
//within correct parameters.
}

The problem I am having occurs when attempting to validate the values in the
TextBox controls. What seem to happen is that the Validating and
SelectedIndexCh anged events fire asynchronously. When stepping through the
code, the Validating event fires and then he SelectedIndexCh anged event fires
before or during e.Cancel being set to true.

The order of event firing that I expect from this operation was Validating,
and then when e.Cancel is set to true, the SelectedIndexCh anged event is
never allowed to fire. This operation is necessary for the project I am
currently involved in.

I have tried a couple of workarounds for this problem, but none have been
satisfactory. If I am using this feature incorrectly, or if there is a
viable workaround for this issue I would appreciate anyone's input. I have
tried using the ItemActivate event of the ListView control, but require a
single-click to a ListViewItem to update the contents of the GroupBox.

I have been struggling with this issue for a few minutes now, and appreciate
you taking the time to read my issue.

Thanks,

PeacError

Nov 17 '05 #1
0 5430

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
602
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 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,...
2
3007
by: David Anderson | last post by:
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...
10
1895
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:
3
10399
by: n. Smith | last post by:
Hi All, Is it normal that the ListView fires the selectedinexchange event twice? I have a LvLoaners list view item that updates 3 text boxes (code below), when I click on an item. I have set MultiSelect to False. The first click goes as planned, but all subsqequent clicks seem to fire the event twice. The first firing triggers an ArgumentException, resulting in nItem not being initialised. That's why I have the first
6
22201
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
2
7381
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 the value of the previously selected record. For example, if the ListView looks like this:
12
4048
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, no items are selected. When the first item is selected by clicking either the left or right button, the SelectedIndexChanged event fires but not the MouseUp event. After the first item is selected and another item clicked on, both the...
4
4532
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 is that when clicking on the "Show details" button the ListView for the appropriate row binds in the codebehind and displays the detail data for the selected row. I did something similar with a gridview control previously, but want to be able to...
6
4723
by: Mike | last post by:
Is there a way to get a ListView control to fire its SelectedIndexChanged event like the ListBox control? When the user selects multiple items at once, the ListView fires the event as each item gets selected. The ListBox waits to fire the event until all selections are complete. Thanks, Mike
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.