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?
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?
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]...
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]...
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
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:
I would like to sort a list of strings which represent paths. The sort result will do have a hierarchical order. What I mean is: for each directory path, I want to list all files in that path (alphabeticaly or not doesn't matter) in first time. Then, each subdirectory path will be listed. For each subdirectory, I want all files..
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
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?
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.
I need to sort a list (of person) to person.Age within person.Department. f I user personlist.sort with a comparer for Age and then sort again with a comparer for Department, the sequence of age is destroyed.
In 2007 I created a program that reads weather data into a listview. When a user clicks on the column header it fires off the column click event handler which calls the Sort Wrapper function. The Sort wrapper will re-order items either in ascending or descending order.
I have never been able to get negative integers to sort properly. I have created a stripped down listview program with a few numbers in the grid for testing. (see attached program zip file).When you run the program, click on the column header that says "Val" and you will see right away that the numbers do not sort correctly.
I have a lists of different custom classes and each must be sorted severals times before the algorithm is complete. For each sort I wrote a comparer. Sofar so good. Everything works. But: By now I have abou a dozen different comparers in more than one class and it is still getting more. I wonder if there is a way to limit the number by writing a new general function that can be used to sort all lists without the need for a specific comparer.Below is what I've got so far. But it does not work.
"System.Collections.Generic.List(Of ClassA)" can not be converted into "System.Collections.Generic.List(Of Object)."
I'm looking for a simple and efficient way to sort up to 60,000 strings that are 3000 chars long in reverse order and save them back out to a text file.
I originally thought of a doubly linked list, but then I realized that we aren't privileged enough to have pointers.
Is there some other way I can create an efficient linked list without pointers?
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.
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 '
I'm using a Listview in VirtualMode, so I can 'add' a lot of files almost instantly. A Listview in VirtualMode does not allow sorting, so I need to sort the data myself. The data is stored as a List of Structure (it's faster to load than a List of ListViewItem). The code below works fine, but I need to sort based on multiple variables in the Structure. Code:
I have a list of collection of points on the screen. I want to order them based on their distance from a seperate, independent point. What's working is I have a function GetDistance which does the dirty pythagorian work of returning the distance between two points.
'Create the set point from which to start all measurements from (startpoint) dim SetPoint as new Point(200,200) 'Create a list to hold arbitrary points to test (endpoints) dim ListOfPoints as new list(of point)
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:
It is possible to catch an exception and throw a new exception which wraps the first exception as an inner exception: [URL] Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute? If so, and it is of a higher exception type, is this not wrapping the exception? eg I can throw exception ex of type IndexOutOfRange, log it but rethrow, catch a higher up exception and do something, or I can throw a new exception and wrap an inner exception like:
I'm having my program sort an excel sheet by a few columns. However, it is only sorting by the first column not the rest that I specify.ere is my sort code below:
I have a WPF ObservableCollection which is bound to a ListBox and I have a Sort() method which when called will convert the ObservableCollection to a List(Of T), and undertakes a sort based on a date/time column within the collection.
The data is sorted, even when new items are added to the ObservableCollection, however the date/time isn't being correctly sorted. The data is sorting based on the date however it is very much random when it comes to the time portion. The following is an example of the outcomes I am experiencing:
[Code]...
Is there anything that I am doing incorrectly in this method that would cause the time portion not be included in the sort? Is there a better way of doing a sort?
I have a List(of String()). I have written a custom comparer (implements IComparer(of string)) to do an alphanumeric sort.Is there a way to sort the List using a given index to determine which position in the String() to sort by? In other words one time I might sort by Index = 0 and another time by Index = 3. The length of all String() in the list is the same.For reference this question is similar to Sort List<String[]> except I am using VB.net and that question is hardwired to Index=0.
EDIT from OP's comments:I started simple with the non custom comparer but I am getting an error: expression does not produce a value. Not sure what I am doing wrong.Here is the code:
Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String()) Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex))) End Function
I have an ASP.Net form where I use a DropDownList control to display data retrieved from a table. However setting the SelectedValue of the DropDownList to a value not existing in the dropdown list does not trigger an exception.