473,396 Members | 1,975 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,396 software developers and data experts.

ListView SelectedIndexChanged 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
SelectedIndexChanged 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
SelectedIndexChanged 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 SelectedIndexChanged 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 SelectedIndexChanged 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_SelectedIndexChanged(object sender, System.EventArgs e)
{
//Update GroupBox fields with currently selected record
this.updateGroupBoxFields();
}

private void GroupBox_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
//Cancel the operation if field validation fails
e.Cancel = !this.checkFormFields();
}

private void GroupBox_Validated(object sender, System.EventArgs e)
{
//Validation has succeeded, update the current record.
this.updateCurrentRecord();
}

private bool checkGroupBoxFields()
{
//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
SelectedIndexChanged events fire asynchronously. When stepping through the
code, the Validating event fires and then he SelectedIndexChanged 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 SelectedIndexChanged 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 5392

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...
2
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...
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:
3
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...
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
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
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,...

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.