Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,064 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,593 people online right now. Registration is fast and FREE... Join Now!




How to search thru Array based on value of the combobox?

 
Reply to this topicStart new topic

How to search thru Array based on value of the combobox?

Yagnesh Patel
8 Apr, 2008 - 02:09 AM
Post #1

New D.I.C Head
*

Joined: 8 Apr, 2008
Posts: 1

Hi,
I want to search the array of user-defined object, say user-defined class is as below.
CODE

public class ServiceTypes
     {
     public int ServiceID;
     public string ServiceName;
     public int VendorID;
     }


On the windows form, I have one combo box control thru which I can get VendorID.

Now, I want to search thru the ServiceTypes - array based on the value of VendorID selected in the combo.

Note: I can not use Array.FindAll, as I need to search ServiceTypes based on the value selected in VendorID combo.

Can anyone help to find good performance solution? - I know about search thru the array and prepare new based on the VendorID.

Thanx
Yagnesh
User is offlineProfile CardPM
+Quote Post

baavgai
RE: How To Search Thru Array Based On Value Of The Combobox?
8 Apr, 2008 - 03:42 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
QUOTE(Yagnesh Patel @ 8 Apr, 2008 - 06:09 AM) *

Note: I can not use Array.FindAll, as I need to search ServiceTypes based on the value selected in VendorID combo.


You can use FindAll, you just have to know how to ask the question. wink2.gif

Here's the code:
csharp

ServiceTypes[] FindAllTest(ServiceTypes[] list, int vendorId) {
return Array.FindAll(list,
delegate(ServiceTypes item) { return item.VendorID == vendorId; }
);
}


Also, look into List<ServiceTypes>, it's generally a better solution to an array. Delegates are exceptionally useful tools. If you start to use Generics, then even more so.

Hope this helps.

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:39PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month