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

Iteration Methods

Say I have a listbox and I need to go through each entry in the same order
that the are identified in the listbox. I know if I create my own counter an
manually update the counter as I process each item in the Listbox that I will
always process them in the order in which they are contained in the listbox.
If instead I used the "foreach" convention of iteration, can I be assured
that I will process them in the same order that they exists in the listbox?
Nov 20 '05 #1
2 1056
Yes.
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected)
{
//do some processing
}
}

--
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
-----
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jim Heavey" wrote:
Say I have a listbox and I need to go through each entry in the same order
that the are identified in the listbox. I know if I create my own counter an
manually update the counter as I process each item in the Listbox that I will
always process them in the order in which they are contained in the listbox.
If instead I used the "foreach" convention of iteration, can I be assured
that I will process them in the same order that they exists in the listbox?

Nov 20 '05 #2
Hi Jim,

foreach depends upon the item counter in the Collection's implementation. I
believe the ListBoxItemCollection class assures you that they will be
processed in the same order as in the ListBox.

HTH,
Altaf
--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com
"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
Say I have a listbox and I need to go through each entry in the same order
that the are identified in the listbox. I know if I create my own counter
an
manually update the counter as I process each item in the Listbox that I
will
always process them in the order in which they are contained in the
listbox.
If instead I used the "foreach" convention of iteration, can I be assured
that I will process them in the same order that they exists in the
listbox?

Nov 20 '05 #3

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

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
31
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The...
2
by: Abdullah Khaidar | last post by:
Is there any iteration style we must use to get faster processing time? I've tried with some style to concat number in list. But I still don't know which one is the recommended style. >>> def...
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
0
by: Michael B. | last post by:
Hi All! I have a question regarding usage of iteration methods. I found in one methodology that the first example of iteration is strongly recommended over the second one (stated below). Could...
23
by: Mitchell Vincent | last post by:
Is there any way to "skip" iterations in a for loop? Example : for x = 1 to 10 if something = 1 next endif
6
by: omesh | last post by:
hi guys.. i got a problem.. could anyone help me write a program.. the program is as follows:- 2. Solving systems of Linear equations using Iteration: You are required to write a C++ program...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...

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.