473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to sort List<T> on two criteria at same time.

Hi,
I am working on the project where i show a list of Log Records.

my list is as follows.

Original list
Id Time Event Details
1 1 Error1 xyz
2 1 Error3 xyz
3 1 Error2 xyz
4 1 Error1 xyz
5 1 Error2 xyz


I first create the custom object of (Id,Time,Event, Details) and value (1, 1, Error1, xyz).
I call it TableRowElements.

like this i create List<TableRowElements>.

Now I want to sort the record according to Event but while doing that i also need to see that Event are in order

for example

Final List should be

Id Time Event Details
1 1 Error1 xyz
4 1 Error1 xyz
3 1 Error2 xyz
5 1 Error2 xyz
2 1 Error3 xyz

I am using Icompare for this .

I am getting the values sorted but only on 1 field 'Event'. After sorting the list does not keep its order.

I am not sure how to sort this list on 2 criterias. I am working on WinCE 6.0.

Thanks,
Sachin
Nov 11 '09 #1
3 3668
Plater
7,872 Expert 4TB
If you are overriding the Compare function , you can decide explicitly what order they go in.
Nov 11 '09 #2
Issue is not that.

I am able to sort the record on the 'Event' names but after sorting it is not able to maintain the chronological order i.e. the order of the 'Id'.

Id Time Event Details
1 1 Error1 xyz
4 1 Error1 xyz
5 1 Error2 xyz
3 1 Error2 xyz

2 1 Error3 xyz

it should be
Id Time Event Details
1 1 Error1 xyz
4 1 Error1 xyz
3 1 Error2 xyz
5 1 Error2 xyz

2 1 Error3 xyz

i also want to know whether the sorting can be possible for two fields as we do in the database i.e. order by Event, Id
Nov 12 '09 #3
Plater
7,872 Expert 4TB
So in your compare function sort FIRST on the ID, then sort on the Event
Nov 12 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
4
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding C++ programming language standard. It is related to standard library, not to the core language. Is it portable to instantiate template class std::list<>...
4
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>....
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
44
by: Zytan | last post by:
The docs for List say "The List class is the generic equivalent of the ArrayList class." Since List<is strongly typed, and ArrayList has no type (is that called weakly typed?), I would assume...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
1
by: Jonathan Wood | last post by:
I see that I can create a List<stringlist and bind it to a GridView control (by setting the DataSource property to the list and calling the DataBind method). What's the trick to doing the same...
4
by: =?Utf-8?B?SkI=?= | last post by:
Hello List<Tis said to be more powerful than ArrayLists but if you have something like this: List<intmylst = new List<>; myList.Add("Joe"); myList.Add(25); the list doesn't seem to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.