troubleshooting Question

How to sort a List of Non-Generic Data?

Avatar of LongFist
LongFistFlag for United States of America asked on
Visual Basic.NET
8 Comments1 Solution357 ViewsLast Modified:
Hi Experts!

I have a structure that I make a list of to contain basic inventory stuff.  It looks a lot like this:
    Public Structure inventoryPartInfo
        Dim partNumber As String
        Dim partDescription As String
    End Structure

...and I'm really digging the List (of T) feature in VB.Net to allow me to more cleanly deal with my arrays of Inventory Parts:
    Dim microController As New List(Of inventoryPartInfo)

To add a "row" of data to this List is really pretty simple:
    Dim newControl As New inventoryPartInfo

    newControl.PartNumber = "11435-AC-AB-X"
    newControl.PartDescription = "Cirrus Dual-Band Gate"

    microController.Add (newControl)
    newControl = Nothing, I have a need to sort this list, but the default List.Sort() fails because it's trying to compare two structs, and has no default method for this.  All of the examples I keep running into are for "Generic" data, which almost always refers to a list (Of String) or a list (Of Integer) - neither of which apply here.  I've been studying Lambda functions, but nothing I attempt seems to meet with anything other than an error condition.

If my input data looks like this:
          11435-AC-AB-X     Cirrus Dual-Band Gate
          23907-FX-BA-W     Rabbit Data Manifold
          21340-TF-AB-A     Drax Ring Buffer
          54384-FX-BA-A     Prillex Transfer Enhancer

...I need to be able to sort it (on PartDescription) to look like this:
          11435-AC-AB-X     Cirrus Dual-Band Gate
          21340-TF-AB-A     Drax Ring Buffer
          54384-FX-BA-A     Prillex Transfer Enhancer
          23907-FX-BA-W     Rabbit Data Manifold

...maybe later I might need to sort it (on PartNumber), but that is obviously a string, too, so the same [sort] function might apply, only to a different "field" value (PartNUmber) instead of (PartDescription).

Does anybody know how this may be achieved?  I'm fairly certain that it's something small that I'm overlooking - I can't shake the feeling that this should be pretty simple.

Thanks for your assistance!
- The Lurking LongFist
Mike Tomlinson
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros