VS 2008 Sorting A List(of Class) Using LINQ?

Apr 30, 2010

I'm using the following code to sort a List(of Class) using LINQ. It works fine, but I'm wondering if there is a better way to do it. I'm basically taking one list, applying LINQ to it, then using the result to create a second list in the sorted order. Can I do this without creating a second list? Here is my sample

' KeyMatch is my Class Variable
' mMatchList is the Unsorted List
'

[code].....

View 3 Replies


ADVERTISEMENT

Vb.net - Sorting A List Of <Object> With VB And LINQ

Mar 1, 2012

I'm trying out some LINQ expressions and can't get them to work with the List class. Basically I want to be able to sort a list of custom objects by property type, however the C# LINQ syntax is KILLING me and I can't figure out how to convert it to VB

Class Foo
Sub New(Name As String, Position As Integer)
Me.Name = Name

[code]....

View 2 Replies

Sorting A List By A Class Value

Jun 25, 2011

I have a list (i.e. Dim nList as new List(of className)). Each class has a property named zIndex (i.e. className.zIndex). Is it possible to sort the elements of the list by the zIndex variable in all of the elements of the list?

View 4 Replies

Convert A List Linq Expression To Defined List Class?

May 26, 2012

y have this class

Private Class MyClass
Public Property propertyOne() as String
Public Property propertyTwo() as String

[code].....

View 2 Replies

VS 2010 Sorting A Listbox (after Trying To Copy Class Instances Properties To A Temp List)

Jan 25, 2012

I'm trying to figure out a way to sort the entries of a listbox... but in a different way instead of the obvious one (sorted property). First of all, I need to explain how the items are populated at first:

[Code]...

View 19 Replies

.net - Populating A List Box With Variable Names From LINQ Generated Class?

Nov 17, 2009

I'm quite new to Visual Basic - using Visual Studio 2008 and can't seem to find a way to do the following:

I have a few tables in a SQL Server database and have used LINQ to SQL to create classes of those tables.

Here's a cut down example of what I'd like:listbox1 filled with table names - APS, SMPS, WCPC, CFLAPS
Then from the SelectedIndexChanged event, listbox2 should populate column headers of the selected table.

I have no issues getting data from the database, and can access all of these headers through the anonymous type objects created from a LINQ query (eg APS.ID, APS.count etc), but populating a listbox with these variable names rather than the data inside them seems rather elusive.

This is probably a cross platform coding question rather than VB specific, so if you have a solution in C# or whatever I'd be happy if you could let me know.

View 2 Replies

List View Sorting In Vb 2008?

Dec 28, 2009

how we can sort a listview on column wise in a simple way?

View 2 Replies

VS 2008 Double Sorting Of A List?

Jan 19, 2010

I have been learning how to sort a list using lambda functions

excessPop.Sort(Function(f1, f2) f1.ID.CompareTo(f2.ID))

I am however struggling to sort a list using 2 parameters within a lambda function. The properties within my list that i need to sort by are Category and then by Cost. how to do this?

View 5 Replies

[2008] Sorting A List Within A Form By Name?

Feb 7, 2009

One displays a list of contributors for a charity and the amount given in a text box.However iv created another button but i need this to sort the list of names to just display the names and in alphabetical order.

[Code]...

View 19 Replies

VS 2008 Extracting Best Laptime And Sorting A List

Aug 22, 2011

So I'm working on this school project where I'm supposed to add names and laptimes from textboxes to a list. I've got that sorted out with some help from Shaggy_Hiker (thanks!). Now what I'm trying to do is get the best laptime from the list of entries and display that in a label. I also want to sort the list by laptimes in ascending order, and I've tried the.Sort method without too much luck + all entries with a laptime over 60 min should be disqualified.

(I'm thinking of adding all of these to a seperate list which I've named feilreg, but right now all entries that doesn't meet the right criteria like empty textbox, negative laptime and so on gets saved to that list. I'd like to make it just entries over 60 min) I also can't seem to figure out why a laptime of say '32.45' won't register, it has to be with a comma like '32,45'. I've got a function in my class 'Rundetid' to format the output to two decimals maximum.

[Code]...

View 6 Replies

VS 2008 Adding Class Object To List Or Array In A Different Class

Jun 21, 2010

I am trying to create an list or an array of a class.Here is my "Ingredient" class that I am trying to create a list of:[code]In my "recipe" class, I am want to create a list (or array) and I am drawing a big blank on how to do it. Can anyone point me in the right direction?

View 2 Replies

.net - Sorting A Dictionary By Value With Linq?

Mar 23, 2012

I'm trying to sort a dictionary by value with LINQ but I can't figure how the ToDictionary() method works.

All the examples I can find are in c#.

here's my code

Dim f As Dictionary(Of String, String) = (From value In projectDescriptions.Values
Order By value Ascending
Select value).ToDictionary(???)

[Code].....

View 3 Replies

VS 2008 Datatable To Class Object Using LINQ

Sep 29, 2011

I have a datatable being returned by my DAL. In my BAL I want to return a class object. So I have a class called BusinessArea that has ID, Description and Active properties. I tried this:

[Code]...

View 2 Replies

Linq Partial Sorting Items?

Aug 19, 2011

I have an issue for ordering items using Linq[code]...

View 4 Replies

VS 2008 : Get Fullnames From List (of String) Using LINQ?

Oct 18, 2010

I have this vb code in my asp.net webservice.

<WebMethod()> _
Public Function GetUsers(ByVal prefixText As String, ByVal count As Integer) As String()
Dim UsersList As New List(Of String)

[code]....

However, This returns all the users from my user table. I want to get just the users where the fullname is like the prefixtext variable that is passed in to the function.Now I need to use LINQ(the only way I can think of). But how do I change my code.

View 9 Replies

VS 2008 Get Original List Index Of LINQ Query

Oct 24, 2010

If I use a LINQ query over some type of collection, is there any way to know the initial index of an element of the result?

Purpose: I make a query to set as source of a DataGridView, and on a (button)cellclick event I want to a call a method that needs to reference the collection at the correct index.

View 13 Replies

Asp.net Mvc - Sorting Datatable With Linq With Correct Datatype Of A Column?

Mar 27, 2012

I have this code that use to sort a datatable.

Dim sortingIndex As Integer = orderby
Dim DataTableNew As DataTable = New DataTable
DataTableNew = dt.Clone
Dim query = (From c In dt.AsEnumerable Order By c.Field(Of String)(sortingIndex) Ascending)
query.CopyToDataTable(DataTableNew, LoadOption.OverwriteChanges)

My problem is that with this method I always need (Of String) for it to work, so the date columns are also managed as Strings witch is the problem. Is there a way to use the correct type so the sorting is based on the type of the column?

View 1 Replies

C# - LINQ Select From IEnumerable With Distinct/GroupBy And Sorting?

Oct 19, 2010

My particular example is fairly complex but I think the concept would apply equally to something like a logging system so I'll use that instead for ease of explanation. It's a ficticious example, please don't harp on or agonise over what is achitectually, programatically or morally wrong with the example itself

[Code]...

I don't want to 'cheat' and resort to a long-winded way of doing it when performance isn't critical here and I'm moderately confident it can be done in a single LINQ statement.

View 1 Replies

VS 2008 - List Of Class(Of T) ?

Aug 15, 2011

If i have the following class:

Is there anyway to load classes derived of this class into a single list kind of like: list(of Test) so that i can itterate through all items and call the load sub in each?

I.E.:

CODE:

View 3 Replies

Sorting A Class Of Multiple Properties?

Oct 13, 2011

I have created a Class, basically like this:

Public Class Person
Implements IEquatable(Of Person)
Public Sub New(ByVal Name As String, Optional ByVal Like As Boolean = True)
Me.Name = Name

[Code]...

View 4 Replies

Exception When Sorting List

Jan 29, 2010

I'm trying to sort a List of objects with a generic comparison.I get an exception when the property on which I'm sorting happens to be null in one of the objects.VB.NET 2.0, web.i've read several posts on this exception, and still don't get it.[code]It is true that this only happens on properties which happen to be null somewhere in the list.Sometimes I sort on other properties which happen to always be always non-null (using a different, but similar, comparison method), and this technique works just fine.I've tried to implement the CompareTo for both IComparable and IComparable(of FollowupSurvey) so I could capture this exception while debugging, but netiher actually get invoked (despite what it seems like the exception is telling me). At this point, I don't have a CompareTo in my FollowupSurvey object; thus, it's using Object's.It doesn't seem as if I can really help if the base CompareTo doesn't reutrn 0.anyone have any idea what this exception really means, and how to make sorting work properly?

View 2 Replies

Sorting A List Of Objects?

Mar 16, 2012

Suppose I have:

Public Class myClass1
Dim foo As String
Dim bar As String

[code].....

View 23 Replies

Sorting Within A List Of Type's?

Jan 30, 2010

I have a simple type like:-

[Code]....

if I have a list of type top_params then how can i sort the list based values in the k_sig_level field?

View 2 Replies

VS 2008 List (of Class) In A DataGridView Question?

Oct 10, 2009

I have a List(of Class) where the class has two properties. One is a string and the other is a List(of String). I want to view this in a DataGridView and show the list property in a combobox. This is the basic structure of the grid, can someone tell me how I assign the "Files" property to the combobox? [code]

View 10 Replies

VS 2008 Removing Items From List Of Class?

Jun 12, 2010

I've searched on the Internet and I can't find a solution to this simple problem. I've also looked on Microsoft's MUCH improved MSDN site and haven't found a solution, so here it goes. I'm trying to remove an entry from a list of class and it doesn't get removed. Here's a sample of the code I'm trying: (I renamed the class and variable names to make it a simple example)

Dim lstClass As New List(Of TheClass)
Dim mClass As TheClass
I tried this first
mClass.filename = "The Entry to Delete"
lstClass.Remove(mClass)

[Code]...

View 3 Replies

Asp.net - Reverse-sorting A Listview (with Comparer Class)

Oct 7, 2009

I have a two-column ListView linked to a Datapager. The ListView lists all files of a particular type in a particular directory, so the data source is an ArrayList of type FileInfo. Consequently, I had to create a Comparer class to use in the ArrayList.Sort method.

[Code]...

View 3 Replies

C# - Sorting List Alphabetically And By Type?

Apr 18, 2011

I have a list of instruments and I need to sort them to the following requirement.

order by:

cash
securities in alphabetical order
managed funds in alphabetical order

I have a list of instrument which has properties name and type, I've managed to sort alphabetically by name.

Instruments.Sort(Function(x, y) String.Compare(x.Name, y.Name))
Instruments.Sort((x, y) => string.Compare(x.Name, y.Name));

View 1 Replies

Marking Duplicates In A List While Not Sorting

Feb 15, 2012

I had a need to mark a listview row if filenames were duplicates for n number of characters from the left. I wrote the following but it smacks of VB6.[code]...

View 5 Replies

Return List After Sorting With Repeater?

Jan 5, 2012

I have a list going into a repeater, sorting with jquery sortable(), and then need to put the sorted list into a session variable. I cannot seem to figure out how to get the sorted values back into a list.[code]...

View 1 Replies

Sorting - List.sort Not Working?

Apr 3, 2009

I have a slightly odd problem that I think is most likely due to an act of foolishness on my part, but for the life of me I (and other members of my team) can't see it.I have an object that contains a generic list property which I would like to sort. I have written a comparer class to do this for me and I am calling it in the following way:baseObject.ListOfThings.Sort(new ThingComparer()I have debugged into my compare function and it is returning the right values.However After the sort call, the list remains unchanged. Have I missed something obvious, or is there something else I need to do.EDIT: Yes I was being a fool, and the property returning a list was recreating it from scratch each time it was accessed

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved