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


ADVERTISEMENT

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

Sorting A List Based On An ArrayList Within A Custom Object

May 24, 2010

I am using a list to keep track of a number of custom Row objects as follows:

Public Rows As List(Of Row)()
Row has 2 properties, Key (a String) and Cells (an ArrayList).

I need to be able to sort each Row within Rows based on a developer defined index of the Cells ArrayList.

So for example based on the following Rows

Row1.Cells = ("b", "12")
Row2.Cells = ("a", "23")

Rows.Sort(0) would result in Row2 being first in the Rows list. What would be the best way of going about implementing this?

View 2 Replies

.net - Searching A List Of Objects In An Object List Using Linq?

Dec 22, 2010

I have 2 classes

Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime

[Code].....

View 1 Replies

Linq - Filtering List Object?

Apr 13, 2011

I am using LINQ - VB.Net I want to filter my List object by passing String object in the where.

Dim _permittedTransactionCodes As List(Of String) = Nothing 'String object

it is populated with data.

Dim tap100transCodeInfos As List(Of Tap100transCodeInfo) = _dal.GetActiveTap100transCodeByHdrScreenCde(UCase(screenId), "TRAN_CDE")

i am trying something below, but not getting the filtered results

tap100transCodeInfos.Where(Function(x) _permittedTransactionCodes.Contains(x.TranCde))

View 1 Replies

Linq To Object: ToList Can Not Convert To Generic List

May 8, 2009

Dim tenItem = From t In _InvalidFeeList _
From i In ItemCount _
Where t.FeeCode <> i.FeeCode _

[Code]....

I am getting "Can not convert to System.generic.list" error. I look all over for this error and it seem like my code should work for example here

edit: I think i should explain what I'm trying to do here. I want to compare two object list and select the object from the InvalidFeeList if the FeeCode is not equal to the object in ItemCount FeeCode and take the first 10 objects from the InvalidFeeList.

View 2 Replies

LINQ Query To Group Data Between Two List Collections, Populating A Nested Object

Oct 26, 2011

I have these objects:[code]Using LINQ I need to take a List(Of MakeInfo) and a List(Of ModelInfo) and aggregate the StockInfo from ModelInfo into the List(Of MakeInfo).So for each MakeInfo I will have a total count of all stock where MakeInfo.Name = ModelInfo.Make, and also a minimum price.I think it's going to be something like this, but I'm having trouble accessing the nested object and not sure if it's going to be possible with a single query.[code]

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

List Of T Find Date Or Other Property In A Object In The List - Then Return Found Object?

Sep 3, 2009

After reading all the examples for list of T exists and Find and find first, none show how to handle multi-property objects. Below is bare bones example maybe someone could flesh out to show how this should be done.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DatePriceList As New List(Of DateAndPrice)
DatePriceList.Add(New DateAndPrice(Date.Parse("1/1/2000"), 10.12))
DatePriceList.Add(New DateAndPrice(Date.Parse("1/2/2000"), 11.12))

[Code]...

View 3 Replies

Linq Partial Sorting Items?

Aug 19, 2011

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

View 4 Replies

Display A List (Of Object) Which Has Single Objects And Child List (Of Object)?

Sep 6, 2011

Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.[code]What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.

View 2 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

Cast A List Of Object To List Of Interface That Object Implements?

May 19, 2009

I am working in VB.net and have a Class, Foo, that implements an interface, IBar.I have a List of Foo's, but I need to pass a list of IBar's into a function, but I keep getting casting errors, even when I use DirectCast.My code is [code]MainWorks works, but it would be really annoying and inefficient to have to do that everywhere I want to call this function.

View 4 Replies

Code Sorting An Object Within Arraylist ?

Oct 12, 2009

Class Murid
Implements IComparable
Public strNama, strKelas As String[code].....

View 2 Replies

Sorting Columns In A Listview Object?

Jun 22, 2009

First off i just want to take a bow to all the vb gods out there..I am trying to implement the sorting class form article 319399 in the knowledge base [URl]..on step number 6 it says to "Paste the following code into the ColumnClick event for the ListView:"so i created a sub to handle the ColumnClick event

[Code]...

View 2 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 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

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

Sorting Objects In Arraylist By One Of The Object's Properties?

Aug 30, 2011

I have a group of objects stored in an arraylist. These custom type objects have a number of properties from their underlying class . I want to use one of the properties to sort the array. I cannot determine which Array.Sort method to use.

I want to sort based on an integer property. Virtually every example I can find involves sorting strings.

So, assume the Objects have the following properties.

Obj.name as string
Obj.ID as integer
Obj.Alive as boolean

The objects are kept in an arraylist called FriendsOfMine.

I want to be able to order the list by Obj.ID, both ascending and descending in value.

View 12 Replies

Error - LINQ To Entities Does Not Recognize The Method 'System.Object IIf(Boolean, System.Object, System.Object)'

Jul 29, 2011

I am getting following error whenever I want to use IIf function inside entity framework query.

LINQ to Entities does not recognize the method 'System.Object IIf(Boolean, System.Object, System.Object)' method, and this method cannot be translated into a store expression.

View 1 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

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

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

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

Sorting A List(Of FileInfo) By 2 Properties?

Oct 3, 2011

I have a List of FileInfo objects that I want to sort by creation date & file size. Is there a way to do that?

View 5 Replies

Sorting Items In A List View?

Aug 15, 2011

I am using the code from hereevelopment/vbnet/code/370426 to sort my listview items. But I want something more 'dynamic': when I click on a header column, I want that it changes the sorting based on the column that has been clicked. here is my code:

'Classes usadas
Imports System.Math
Imports System.IO

[code].....

View 3 Replies







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