searching listboxitems
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?
thanks.
walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
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>();
list.Add(arrList1);
list.Add(arrList2);
//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).
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
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.
walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1