.net - SortedDictionary - Comparer Only For Sorting

Oct 31, 2010

I have a list of keys and values that I would like sorted by key via a custom Comparer(Of T). I tried using a SortedDictionary, but kept getting incorrect results because it used the comparer to see if the items were the same. For example calling SortedDictionary.ContainsKey() would return false, even though it did contain the key.

When I stepped through the code after calling ContainsKey(), it would go to the comparer.Compare(x, y) function. It would then only compare against a few of the keys in the dicionary, and somehow skip the matching item (which I ensured did exist). I take it that this is some sort of optimization, where some items are skipped depending on what is returned by the comparer.Compare() function? Is it possible to have a dictionary that only uses the comparer for sorting? EDIT: I am using a Type object for the dictionary's key

[Code]....

View 3 Replies


ADVERTISEMENT

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

Use Custom Comparer When Sorting By Multiple Columns?

Apr 7, 2011

I have a ListView (GridView) that I want to sort by 2 columns, so if 2+ items have the same value in Column 1, it sorts by Column 2. Pretty easy. But empty strings show up at the top when sorting A-Z. I'd like to move them to the bottom. I made a comparer (IComparer) that takes care of this, but I'm not sure how to use it.[code]...

View 1 Replies

LINQ Except Using Custom Comparer?

Jun 17, 2009

[code]....

View 4 Replies

Using SortedDictionary As Combobox Datasource?

Mar 24, 2010

I have a combobox which i am binding to a sortedDictionary list, so it displays in ascending order. My question is, I need to display "--Select--" as the first option. Is there any way to either:

1) add another item besides for the datasource

or

2) add an unsorted item to the top of the sortedDictionary

View 2 Replies

VS 2010 Using A Combobox With A SortedDictionary?

May 21, 2010

I have a SortedDictionary of type (String, UserPrincipal). The key is the user's UserID and the item is the user's UserPrincipal object.I have bound the combobox to the dictionary like this

ManagersComboBox.DataSource = New BindingSource(_userdict, Nothing)
ManagersComboBox.DisplayMember = "Value"

[code].....

View 2 Replies

Use SortedDictionary To Store 65,000 Keyvalue Pairs?

May 17, 2012

I'm thinking to use the SortedDictionary to store 65,000 set of keypairs and from time to time during my program execution, I need to retrieve the value from the this dictionary. May i know will there any concern especially in term of speed of execution if i use this method as above? Is there max. capacity that a dictionary can hold?

Previously, i was thinking to use a simple 2D array to do this, but it mights slow things down because in order to retrieve the value, i might need to loop through the whole array till i found the value that i want.

View 1 Replies

IQueryable OrderBy Error: Cannot Order By Comparer

Sep 14, 2011

I'm trying to sort a IQueryable dynamicaly.

Dim activities =From a In db.VW_Activities Select a
activities = activities.OrderBy(Function(a)
New ActivityComparer(SortFields(0).Sort))
definition of SortFields:

[Code]...

View 3 Replies

Change SortedDictionary Behavior To Sort Words Beginning With First?

Dec 28, 2009

I'm using a SortedDictonary(Of String, String) in my application, and I experience a strange sorting behavior. Consider the following code example:[code]I would expect the keys to be sorted as "'A", "'B", "'C", "A", "B", "C", which is what you get when comparing the keys "by hand", through the < operator. And yet, iterating through the keys returns "A", "'A", "B", "'B", "C", "'C".How can I change the SortedDictionary behavior to sort the words beginning with ' first?

View 3 Replies

Implementing IComparer For Custom Objects After Converting A Dictionary To SortedDictionary?

Jun 5, 2012

I'm having trouble implementing an IComparer method. Essentially, I want to compare the properties of two custom objects (the properties are of type integer).dE is a Dictionary(Of String, customObj)prTabIndex is a property of customObj and is of type Integer (these hold true for all examples)After some more searching I found this thread which suggested 3 things: a List approach, utilizing LINQ, and using some C# 3.0 features. I've tried three different ways:...rolling my own IComparer implementation:

Public m As Sub(ByRef d As Dictionary(of String, customObj))
Dim sortedD As New SortedDictionary(Of String, customObj)(d, myCompare)
End Sub

[code]....

Note that VS2008 has underlined 'dE.ToDictionary...' (to the end of the line) and giving me two messages depending on where I hover my mouse:

1) "Data type(s) of the type parameter(s) in extension method 'signature' As 'signature defined in 'System.Linq.Enumerable cannot be inferred from these arguments. Specifying the data types explicitly might correct this error. Seen while hovering over "ToDictionary".

2) Nested function does not have the same signature as delegate 'signature'. Seen while hovering over anything after "ToDictionary".

Q1) How far off am I in each of the implementations?

Q2) Which one is the computationally least expensive? Why?

Q3) Which one is the computationally most expensive? Why?

View 1 Replies

VS 2010 - Write A Custom Comparer To Make A Listbox Full Of Numbers Sort Itself

Jan 17, 2012

So...numeric sorts. Do I really need to write a custom comparer to make a listbox full of numbers sort itself like:

[Code]...

View 4 Replies

Excel Sorting Is Only Sorting One Column Not Multiple?

Mar 12, 2012

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:

myRange.Sort(Key1:=myRange.Range("A:A"), Order1:=XlSortOrder.xlAscending, Key2:=myRange.Range("G:G"), Order2:=XlSortOrder.xlAscending, Header:=XlYesNoGuess.xlYes, Orientation:=XlSortOrientation.xlSortColumns)

[code]...

View 1 Replies

Wpf - Sorting Observable Collection Incorrectly Sorting?

Aug 20, 2011

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?

View 1 Replies

.net - Sorting And Getting Uniques?

Dec 30, 2009

i have a string that looks like this "apples,fish,oranges,bananas,fish" i want to be able to sort this list and get only the uniques. how do i do it in vb.net? please provide code

View 3 Replies

Asp.net - Sorting A Dictionary By Value?

Apr 19, 2010

I have a dictionary in the form of: { "honda" : 4, "toyota": 7, "ford" : 3, "chevy": 10 }

I want to sort it by the second column aka (the value) descending.

Desired output:
"chevy", 10
"toyota", 7
"honda", 4
"ford", 3

View 3 Replies

File Sorting Using VB?

Jan 23, 2012

how to sort the files in the directory ?i'll have more than 500 no of files in the below format.

prod_orders_XXX_<TimeStamp>.dat
XXX = symbol of the product and the length may varies between 3-6.
<TimeStamp> = date and time

Multiple files for the same XXX are possible with different time stamps.Here are some examples:

prod_orders_abc_20122001083000.dat
prod_orders_abc_20122001083111.dat
prod_orders_xyz_20122001093157.dat

[code]....

View 1 Replies

SortedList Not Sorting On Key?

Mar 24, 2009

I have a the need for key value pair that I wish to sort so I decided to use a SortedList instead of a HashTable.I am adding the data in the order below to my SortedList which is the order I need it in

Key | Value
--------------------------------
1 "700-800" | List(Of Object)
2 "900-1000" | List(Of Object)

[code]....

The key is a string and the value is a List of objects. The key is representing a time slot that has been concatenated from two integer values and delimited by "-". "700" as a string was 0700 initially an integer.e.g.

Dim key As String = slotTimeStart.ToString() & "-" & slotTimeEnd.ToString()

But once these key value pairs are added to the SortedList they appear in the order

3 "1100-1200" | List(Of Object)
4 "1700-1800" | List(Of Object)

[code]....

Unfortunately I recieve the times slots as two integer values which cannot be changed.Is there any way to force a sort on a SortedList? or is this problem because of the way I am storing my key? Is there a better way to store it?

View 4 Replies

Sorting A CSV File From Within An App

Mar 25, 2009

I have a VB.Net 2005 application in which I access a SQL Server DB to pull data into a Dataset. Within my app, this dataset is read sequentially. Then, a cross reference file is read against the dataset record. If there is a match (based on 2 fields from the dataset record), a field value from the cross reference file is used to replace a certain value in the dataset record. Once a dataset record has been read and processed...it is written to a new CSV file. This CSV file contains 5 columns.

I've been requested to now sort this new CSV file using 3 of the 5 columns as the "Sort Key". What would be the fastest way to do this?

I know one way would be to create a new dataset and insert the finished record into this new dataset in the order of the 3 fields (which I'm not sure how to setup).

View 8 Replies

Sorting A DataView?

Mar 9, 2011

I have an XML that looks like this:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="library.xslt"?>
<Library>

[code].....

View 5 Replies

Sorting A Recordset In Vb?

Feb 11, 2009

How to sort a recordset using vb 6.0 coding?

View 2 Replies

Sorting Arrays In .net?

Aug 10, 2009

I need to know if there is any simple way to sort an array in visual Basic.net. I have been trying for some time without any real reliable results or wierd results. Here is the code this is the sort routine which transfers a csv text file read earlier into an array.

Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
Dim i As Integer = 2 'inner loop
Dim j As Integer 'outer loop
Dim tempstore As String = String.Empty
ProgressSort.Minimum = 0

[Code]...

The data seems to be read into the array but the sorting takes a very long time and I am not sure if it is working or not. I have read from other forums that it is easier to sort the array read from csv before splitting it. This record I am trying to sort is 250 records long. I have no idea how long that should take. Not even sure if the algorithm I chose is correct.

View 5 Replies

Sorting In Datagridview

Jun 11, 2009

I have a problem with sorting in datagridview. I load an xml file in a datagridview and I sort the collums for check. when I try to sort it according to it's number the sorting goes like this:

[Code]...

View 2 Replies

Sorting In Datagridview?

Jan 14, 2010

I have two columns in a datagridview, one is a year and the other is a month. These two form a date, but unfortunately the structure in the database I'm forced to use is that of two integers. I need to sort the rows by date, using these two integers. I tried creating an unbound column with a date, but sorting this way seem quite difficult. So, I thought I could do a multicolum sorting by year first and then by month using two columns

View 1 Replies

Sorting Of 2 Strings?

Jun 7, 2009

I have 2 strings one index: 4, 2, 5, 3 and second one times: 205, 153, 320, 300. I need to sort second string ascending, but to change also positions of elements for the first string and maintain position which corresponding with position for second string:For example initial i have:

index: 4 2 5 3 2 4 3 5
time: 205 153 320 300 after sorting 153 205 300 320

View 10 Replies

Way To Disable DGV Sorting

Aug 31, 2010

How do I disable datagridview sorting?

View 1 Replies

Wpf - Sorting XML Data In .NET?

Jul 1, 2010

I have this hierarchy of XML

<Chapters>
<Chapter @num="">
<Section @letter="">

[Code]....

There has got to be a simple way of doing this....

View 1 Replies

.net - Natural Sorting A CheckedListbox?

Apr 18, 2012

I've written the following class to create CheckedListboxes that use a Natural Sort algorithm. The overridden Sort() method, however, is not getting fired.(The code within that method is from the MSDN example on how to implement your own sort algorithm on a regular Listbox.)

[Code]...

A CheckedListbox derives from a Listbox, so I figured the Sort() override would work, but I'm stuck as to why it doesn't.I am setting the instance's .Sorted = True, but it's just sorting items using the default algorithm, and not the Natural Sort algorithm (which has been tested and shown to work as expected elsewhere).

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

2 Dimensions Array Sorting In .net?

Mar 12, 2011

I am trouble in sorting 2 dimensions array in vb.net. One row has 5 columns. Original array have 3000 rows.How can I get the effective sorting with pdtId. I tried to find googling, cannot get the right answer to me.

(0, 0) = pdtId "string"
(0, 1) = brand name
(0, 2) = category Id
(0, 3) = url
(0, 4) = date

[Code]...

View 2 Replies

Asp.net - GridView AutoGenerateColumns And Sorting?

Aug 31, 2009

gridview sorting in VB.NET: I have a gridview with autogenerate columns = true

<asp:GridView ID="GridView1" FooterStyle-BackColor="Aquamarine"
AutoGenerateColumns="true" AllowSorting="true" OnSorting="Gridview1_Sorting"
AllowPaging="True" PageSize="12" OnRowCreated="GridView1_RowCreated"[code].....

I've declared the sort event handler (OnSorting="Gridview1_Sorting" ), and it works fine.However, then I change the column title (headers as they are in the dataset which I get from the database)

GridView1.HeaderRow.Cells(0).Text = "Document" ' "PROC_UID"
GridView1.HeaderRow.Cells(1).Text = "Process Step" ' "PROC_DOC_UID"

When I set the HeaderRow text, I can no longer click on the title to sort (it also is no longer underlined).How do I correct that?

View 2 Replies







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