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

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_Load_Data = new ArrayList_Load_Data();
myArrayList = myArrayList_Load_Data.Test;
ArrayList myArrayList2 = new ArrayList();

foreach(DataItem myItem in myArrayList)
{
if(myItem.Index >= 0 && myItem.Index < 14)
{
myArrayList2.Add(myItem);
}
}
foreach(DataItem myItem1 in myArrayList2)
{
MessageBox.Show(": " + myItem1.Name + myItem1.Index);
}
}.
Feb 17 '06 #1
4 3595
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

MikeY

"DKode" <dk****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.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:

http://msdn2.microsoft.com/en-us/lib....getrange.aspx

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.

MikeY

"DKode" <dk****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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:

http://msdn2.microsoft.com/en-us/lib....getrange.aspx

Feb 17 '06 #5

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

Similar topics

2
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...
4
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...
2
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...
10
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...
9
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...
33
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...
6
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...
3
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...
6
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.