Reputation: 623
I was using a ListView to display Items but I removed it and I am trying to sort data without having a visual component. what do you guys recommend for this type of data.
Dim eProducts As New Concurrent.ConcurrentDictionary(Of String, String())
eProducts("759504") = {"Nike Shoes", "75.50", "9/29/2014", "Description"}
I need a way to sort products by (ID, Name, Price, Date, and Description). whats the best for this Array, List, Dictionary?
Upvotes: 1
Views: 53
Reputation: 6543
I'd recommend using a class or struct to define a product type for your products.
Then LINQ's OrderBy extension method makes it easy to sort in memory arrays, i.e.
' Example products defined as anonymous types
Dim products() = { _
New With { Key .Id=759504, .Name="Nike Shoes", .Price=75.5, .Date=#9/29/2014# }, _
New With { Key .Id=759505, .Name="Puma Shoes", .Price=69.9, .Date=#9/30/2014# } _
}
' Sort by id ascending
Dim byId = products.OrderBy(Function(product) product.Id)
' Sort by price descending
Dim byPrice = products.OrderByDescending(Function(product) product.Price)
Upvotes: 1