i'm trying to create a search bar where the user searches for an item.

the items are in ArrayList and there is multiple ArrayLists.

I want the user to be able to search for something, from all the available ArrayLists and show the result possibly in another listBox..

ie. user searches for documents,

search returns with all items containing documents which shows in listbox. then the user can click and open that object..

what is the best way to achieve this?


5 Years
Discussion Span
Last Post by walid86

Can you show us some of your code? What type are those array lists? Of custom objects (classes) or some general type, lile string or integer?

Anyway, put then into one collection, and then do a loop through this collection. And try to find what you are looking for.

To create a collection you can use a generic list <T>, where T is array list:
List<ArrayList> arraysCollection = new List<ArrayList>();
//and so on, you can use AddRange method instead of Add too.

Then do the looping:
string keyWord = "something";
foreach(ArrayList list in arraysCollection)
    foreach(YourArrayType item in list) //YourArrayType is custom class, string ot int,...
         if(keyWord == item)
               //item found!!

This is only an example how to do the search, since I have no more info, I can do no more (so far).

ArrayList stat = new ArrayList(); //stationary items
            stat.Add(new ListBoxItem("Corporate Letter Head", "1"));
            stat.Add(new ListBoxItem("Corporate Letter Head Follow on Typing guide", "2"));
            stat.Add(new ListBoxItem("With Compliments Slip", "3"));
            stat.Add(new ListBoxItem("Business Cards", "4"));
            stat.Add(new ListBoxItem("Business Cards Typgin Guide", "5"));
            stat.Add(new ListBoxItem("Corporate Presentation Folder - Cover", "6"));
            stat.Add(new ListBoxItem("Corporate Presentation Folder - Inner", "7"));
            stat.Add(new ListBoxItem("A4 Presentation Cover", "8"));
            stat.Add(new ListBoxItem("DL Envelope", "9"));
            stat.Add(new ListBoxItem("C4 Envelope", "10"));

and then once a specific button is pressed, data source is assigned

b2menu.DataSource = stat;

i'll mess around with your code, i should be able to get it to work, i didnt know about putting the arraylists' into a collection, and then searching that.. makes it much more simple.

thanks for your reply.
i'll have a go, and re post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.