473,769 Members | 5,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Now this is an interesting question

Jax
I have this code, behold:

string message = "Are you sure? You will lose this
customer forever. (Well you'll have re-create from
scratch)";
string caption = "Delete";
MessageBoxButto ns buttons = MessageBoxButto ns.YesNo;
DialogResult result;
result = MessageBox.Show (this, message, caption, buttons);
if(result == DialogResult.Ye s)
{
foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
Customer c = (Customer)lvi.T ag;
alCustomers.Rem ove(c);
//this.lstCustome rs.Items.Remove (lvi);
break;
}
}
}
if(alCustomers. Count<1)
{
this.tabCustome rs.Visible = false;
}

Okay what this code does is delete the selected customer
(the one with image an image index of 1) removes the
ListViewItem from the listview then checks to see if there
are no customers left in the array list, if not it hides a
tab control.

What is entertaining is that if you go through this code
with the debugger and remove the slashed out line (where i
remove the listviewitem) alCustomers will never have a
count of zero.
It will for a little while until it hits the slashed out
line, at that point it regains the customer it previously
removed.
Anyone got any ideas why? (I'm assuming it's something to
do with the tag??)

Any help, as always, greatly appreciated, many smiles and
thanks to repliers.

jax
Nov 15 '05 #1
7 1374
Hi Jax,

Try this:

if(result == DialogResult.Ye s)
{
ListViewItem tobedeleted = null;
foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
Customer c = (Customer)lvi.T ag;
alCustomers.Rem ove(c);
tobedeleted = lvi;
break;
}
}
if ( tobedeleted != null )
this.lstCustome rs.Items.Remove ( tobedeleted);
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jax" <an*******@disc ussions.microso ft.com> wrote in message
news:00******** *************** *****@phx.gbl.. .
I have this code, behold:

string message = "Are you sure? You will lose this
customer forever. (Well you'll have re-create from
scratch)";
string caption = "Delete";
MessageBoxButto ns buttons = MessageBoxButto ns.YesNo;
DialogResult result;
result = MessageBox.Show (this, message, caption, buttons);
if(result == DialogResult.Ye s)
{
foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
Customer c = (Customer)lvi.T ag;
alCustomers.Rem ove(c);
//this.lstCustome rs.Items.Remove (lvi);
break;
}
}
}
if(alCustomers. Count<1)
{
this.tabCustome rs.Visible = false;
}

Okay what this code does is delete the selected customer
(the one with image an image index of 1) removes the
ListViewItem from the listview then checks to see if there
are no customers left in the array list, if not it hides a
tab control.

What is entertaining is that if you go through this code
with the debugger and remove the slashed out line (where i
remove the listviewitem) alCustomers will never have a
count of zero.
It will for a little while until it hits the slashed out
line, at that point it regains the customer it previously
removed.
Anyone got any ideas why? (I'm assuming it's something to
do with the tag??)

Any help, as always, greatly appreciated, many smiles and
thanks to repliers.

jax

Nov 15 '05 #2
Jax <an*******@disc ussions.microso ft.com> wrote:
I have this code, behold:


<snip>

Could you produce a short but complete program which demonstrates the
problem? See http://www.pobox.com/~skeet/complete.html for what I mean.
It does look interesting, but I'd like to get a complete repro to start
with.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Hi,

I think that it may be either that he is modifying the collection that he
is iterating on:

foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
this.lstCustome rs.Items.Remove (lvi);
}
}
Or it may be also due that he is removing the selected element in the
ListView , and he may be handling the ListView.Select edIndexChanged event.

Jax:
Can you place a breakpoint in the ListView.Select edIndexChanged handler ?
( if used ). maybe there lay the answer.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jax <an*******@disc ussions.microso ft.com> wrote:
I have this code, behold:


<snip>

Could you produce a short but complete program which demonstrates the
problem? See http://www.pobox.com/~skeet/complete.html for what I mean.
It does look interesting, but I'd like to get a complete repro to start
with.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
I think that it may be either that he is modifying the collection that he
is iterating on:


Indeed - hadn't spotted that. I'd have expected to see an exception in
that case...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Hi Jon,
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
I think that it may be either that he is modifying the collection that he is iterating on:
Indeed - hadn't spotted that. I'd have expected to see an exception in
that case...


Yes, I would expect that too, but Jax says nothing about an exception, so I
assume it does not happen.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6
Jax
Jon and Ingacio,

Thank you both so much for your replies, I find your input
very helpful.
Unfortunately this is a work problem and i'm now at home
without the code to hand.
I will post up a sample app on monday when I get back to
it.

As far as exceptions go there are none at all, it runs
without a problem.
My main concern is that in modifying the collection while
iterating through it I have messed up something somewhere
and this is a concern because i have used this code
(usually with arraylists or listboxes) quite a few times.
I assumed that the break keyword saved me from any
problems, is that generally the case?

I will try the new code that ingacio recommended, it
sounds a little bit like the fix I applied which was this:

if(result == DialogResult.Ye s)
{
foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
Customer c = (Customer)lvi.T ag;
alCustomers.Rem ove(c);
break;
}
}
if ( alCustomers.Cou nt == 0 )
this.lstCustome rs.Items.Clear( );
}

I'll get back to this on monday and see if it effects the
Arraylist when there is more then one customer as i'm not
certain that i've checked that out properly or not(i think
I have but i'll double check, which is why my fix only
applies to 0).

Thanks again, you're both a credit to this newsgroup :)

jax

-----Original Message-----
Hi Jon,
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******* *************** **@msnews.micro soft.com...
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
> I think that it may be either that he is modifying
the collection that
he > is iterating on:
Indeed - hadn't spotted that. I'd have expected to see an exception in that case...


Yes, I would expect that too, but Jax says nothing about

an exception, so Iassume it does not happen.

Cheers,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

.

Nov 15 '05 #7
The problem was due to additional code in selected item
changed event.
I sorted it but thanks for your help :)

jax
-----Original Message-----
Jon and Ingacio,

Thank you both so much for your replies, I find your inputvery helpful.
Unfortunatel y this is a work problem and i'm now at home
without the code to hand.
I will post up a sample app on monday when I get back to
it.

As far as exceptions go there are none at all, it runs
without a problem.
My main concern is that in modifying the collection while
iterating through it I have messed up something somewhere
and this is a concern because i have used this code
(usually with arraylists or listboxes) quite a few times.
I assumed that the break keyword saved me from any
problems, is that generally the case?

I will try the new code that ingacio recommended, it
sounds a little bit like the fix I applied which was this:

if(result == DialogResult.Ye s)
{
foreach(ListVie wItem lvi in this.lstCustome rs.Items)
{
if(lvi.ImageInd ex == 1)
{
Customer c = (Customer)lvi.T ag;
alCustomers.Rem ove(c);
break;
}
}
if ( alCustomers.Cou nt == 0 )
this.lstCustome rs.Items.Clear( );
}

I'll get back to this on monday and see if it effects the
Arraylist when there is more then one customer as i'm not
certain that i've checked that out properly or not(i thinkI have but i'll double check, which is why my fix only
applies to 0).

Thanks again, you're both a credit to this newsgroup :)

jax

-----Original Message-----
Hi Jon,
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP****** *************** ***@msnews.micr osoft.com...
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT dot.state.fl.us >> wrote:
> I think that it may be either that he is modifyingthe collection that
he
> is iterating on:

Indeed - hadn't spotted that. I'd have expected to see
an exception in that case...


Yes, I would expect that too, but Jax says nothing

aboutan exception, so I
assume it does not happen.

Cheers,

--
Ignacio Machin,
ignacio.machi n AT dot.state.fl.us
Florida Department Of Transportation

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

.

.

Nov 15 '05 #8

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

Similar topics

2
1552
by: pythonUser_07 | last post by:
Is this the correct place to post a jython question? I posted the following in the jython group, but I figured I'd post here too: _________________________________________ I am assuming that the PythonInterpreter environment is not a unique environment from within a jvm. Here is some pseudo code to show what I am talking about 1) create a jython module file, lets call it "mytest"
8
2532
by: ºa¤Ö | last post by:
I find a interesting question, and I cannot solve it @.@ If i want to insert unicode data, I need using recordset.addnew instead of using "insert into table" query or "stored procedure" All unicode data inserted into database through insert query or stored procedure would become a question mark "?" no matter: 1. the field is nvarchar 2. the collpase is SQL_Latin_General_CP1_XX_XX" or
2
4938
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server"; c.Open(); SqlCommand command = c.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "select Customers.customerid, customers.companyname, " +
7
3037
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and gals solve. I use Turbo C++ version 3.0 and WINXP as the operating system. Pls observe the following program. 1 #include<stdio.h> 2 #include<conio.h>
12
1429
by: Dino M. Buljubasic | last post by:
I have two applications App1 and App2. App1 is just checking for new version of App2. If it finds newer version of App2 it will download App1 AND App2. (both of them). That is what I am doing now in my application. I am downloading from an FTP server and I can see download progress. However, when the download is finished, App1 is not updated (which I understand, because its file is being locked in the process of update).
6
3902
by: Claude Yih | last post by:
Hi, everyone. I noticed an interesting thing about fread() this afternoon. Well, I can't see why so I post this message in the hope of getting some explanation. Please help me. I wrote the following code in Windows 2k and compiled it with the gcc(version: 3.2.3) contained in MinGW: #include <stdio.h> #include <stdlib.h> #include <string.h>
26
3649
by: v4vijayakumar | last post by:
Happened to see my old (last millennium) c code. Almost forgot that I wrote it . It is interesting. :-) int sqrt(int no) { int t; no = t * t; return t; }
5
1968
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH +1, INCREMENT BY +2, NO CACHE)". Any rows in that table will kill db2move. EXPORT to IXF succeeds, but attempting to load/import the file refuses to load any rows. The really scary part is that this table...
126
4426
by: jacob navia | last post by:
Buffer overflows are a fact of life, and, more specifically, a fact of C. All is not lost however. In the book "Value Range Analysis of C programs" Axel Simon tries to establish a theoretical framework for analyzing C programs. In contrast to other books where the actual technical difficulties are "abstracted away", this books tries to analyze real C programs taking into account pointers, stack frames, etc.
0
9589
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
9423
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,...
0
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
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
8872
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
7410
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
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.