473,387 Members | 1,492 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,387 software developers and data experts.

Sorting Multiple Columns

Does anyone have a simple example on how to sort using the icomparer class?
I want to be able to sort by two properties of an object.

for example first name lastname.

Here is my code

//Here is my IComparer class that takes the MapItem ojbect the mapItem
object contains first and last name and an ID.

private class MapItemComparer : IComparer

{

private MapItem.MapItemSortColumns m_Column; // Local
MapEntity.VariableSortColumns Enum

private Common.SortOrderTypes m_SortOrder; // Local Sort Order Enum

public MapItemComparer(MapItem.MapItemSortColumns Column,
Common.SortOrderTypes Sort)

{

m_Column = Column;

m_SortOrder = Sort;

}

public int Compare(object x, object y)

{

MapItem MapItemX = (MapItem)x;

MapItem MapItemY = (MapItem)y;

switch (m_Column)

{

case MapItem.MapItemSortColumns.LastName :
switch (m_SortOrder)

{

case Common.SortOrderTypes.Ascending:

return MapItemX.ItemKey.CompareTo(MapItemY.ItemKey);

case Common.SortOrderTypes.Descending:

return MapItemY.ItemKey.CompareTo(MapItemX.ItemKey);

}

break;
case MapItem.MapItemSortColumns.FirstName :
switch (m_SortOrder)

{

case Common.SortOrderTypes.Ascending:

return MapItemX.ItemName.CompareTo(MapItemY.ItemName);

case Common.SortOrderTypes.Descending:

return MapItemY.ItemName.CompareTo(MapItemX.ItemName);

}

break;
}

return MapItemX.ID.CompareTo(MapItemY.ID);

}

}
Nov 16 '05 #1
1 6563
hi
checkout this link , i beleive it has what you want
http://www.devcity.net/net/article.aspx?alias=20020304
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Fairless | last post by:
Customers table - contains Columns: CustID, Surname, Forename, TtlID Titles table - contains Columns: TtlID, Title TtlID is a Foreign Key in the Customers table. I have a Form frmCustomers...
1
by: Chris H. | last post by:
Two Questions.... 1. On the DataGrid, if you click on the column titles it will sort the data on that column and put a little "arrow" to indicate that the grid is sorted on that column. When I...
4
by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
1
by: Steph | last post by:
Hello, i dot not manage to write the code to sort a array on multiple columns. ArrayList people = new ArrayList(); people.Add(new Person("John", "Doe", 76)); people.Add(new Person("Matt", "Dire",...
11
by: dwelden | last post by:
I have successfully used the sort lambda construct described in http://mail.python.org/pipermail/python-list/2006-April/377443.html. However, how do I take it one step further such that some values...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.