473,718 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching ArrayList [C# WindowForms]

Hi Everyone,

I'm am trying to find the best method option for searching through an
ArrayList and getting various items at a time. It could be 0 to 14, 15 to 25
etc,etc. I wish .GetRange(0,45) would give more options than just zero base
to whatever.

Right now, (unless there is a better option) I will keep calling the
ArrayList at various times getting the 15 or less items at a time and put
the items into another ArrayList for my usage. Is looping the best method?
Any and all help is appreciated. A sample code is at follows
private void Get_ArrayList()
ArrayList_Load_ Data myArrayList_Loa d_Data = new ArrayList_Load_ Data();
myArrayList = myArrayList_Loa d_Data.Test;
ArrayList myArrayList2 = new ArrayList();

foreach(DataIte m myItem in myArrayList)
if(myItem.Index >= 0 && myItem.Index < 14)
myArrayList2.Ad d(myItem);
foreach(DataIte m myItem1 in myArrayList2)
MessageBox.Show (": " + myItem1.Name + myItem1.Index);
Feb 17 '06 #1
4 3610
if its not broken, then dont fix it :)

there is probably a dozen different ways to accomplish this. You could
override .GetRange and write your own code for getting the range, or
simply loop like you are doing here.

Feb 17 '06 #2
Txs DKode,

I was just looking to see if there was a better way of getting at my data or
getting at a group of my items. I just wish GetRange would get my data items
at various point GetRange(22,26) instead of GetRange(0,26) when I really
only need the last 5 items. Txs Again


"DKode" <dk****@gmail.c om> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
if its not broken, then dont fix it :)

there is probably a dozen different ways to accomplish this. You could
override .GetRange and write your own code for getting the range, or
simply loop like you are doing here.

Feb 17 '06 #3
according to the msdn, the first parameter is a zero based index, which
implies that you should be able to pass any index to start at:


Feb 17 '06 #4
Txs Again DKode,

After doing the sample at MSDN I summised that I was using the GetRange
wrong. Anyhow I am going to with your origional reply "If it ain't broke"
reply, because I would still need to know where and the amount of data
before using this method other wise I'll just end up getting the dreaded
offset length out of bound exception. Txs Again DKode.


"DKode" <dk****@gmail.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
according to the msdn, the first parameter is a zero based index, which
implies that you should be able to pass any index to start at:


Feb 17 '06 #5

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

Similar topics

by: Randy | last post by:
I'm looking for an easy way to find the value member of an object in a control. I have an ArrayList of a simple class with two properties. One property is "Id" and the other is "CompName" (both stings). On my form I have a CheckListBox and I bind the ArrayList of Company's like so. Clb.DisplayMember = "CompName" Clb.ValueMember = "Id"
by: dotNetDave | last post by:
I have created my own comparer class using IComparer for use with ArrayList.BinarySearch. My class seems to work with BinarySearch, but the problem is that my ArrayList has three items in it and it seems that BinarySearch only searches the first two items. So if I happen to be looking for the last item in the ArrayList, BinarySearch returns that it's not there. Any ideas? David McCarter
by: dotNetDave | last post by:
I have implemented custom sorting and searches on my complex objects (they contain properties and collections) using IComparer and BinarySearch. I knew they before doing a search you had to sort your collection, but I found out the hard way yesterday that it has to be sorted on the same property as you are searching on. Fine. But now my problem is that while displaying this collection data to the user I have to search on a different...
by: C Downey | last post by:
Hello: I have an arraylist storing some very basic objects. The object is very basic, it has 2 properties : ID, and COUNT Before I add an object to the arraylist, I want to check if an object with that same ID already exists in the arraylist. If it does, I would like to increase the count of the matching object inside
by: Paul Nations | last post by:
I've got arraylists of simple classes bound to controls. I need to search through those arraylists to set the correct SelectedItem in the control. The code looks like: Public Class DegreeMaintenance Private arrCipCodes As New ArrayList 'populate reader with data With rdr Do While .Read arrCipCodes.Add(New CipCode(.GetString(0), .GetString(1)))
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for Instance1.PK PK =2 for Instance2.PK
by: Paul73 | last post by:
This is driving me nuts. Someone please help me with this. I have a program that's reading a list of terms to search for. The .IndexOf works fine if the term being searched for is in the first few characters. But it doesn't work if the term is anywhere else in the file. For example. Let's say I'm searching for Notice1. If the record looks like this it'll find it... Notice1","Some data","Some data","Some data"," If it looks like...
by: YASIN786 | last post by:
I am developing a java program which reads all the sentences from the text file and adds them into an array list and when given a word, lists all those sentences which contain the given word. i can load the sentences into the arraylist and serach for a word but i don have an idea on how to load the whole sentence that contains the word i am searching for PLS HELP..
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...
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,...
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,...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.