Solved

List View Sorting by sub-items and numeric values in vb.net

Posted on 2003-10-27
3
384 Views
Last Modified: 2011-10-03
Does any one have any code or method by which we can sort list view by sub items numeric- Basic need to specify some columns as numeric... instead of just text and to sort by multiple columns
Also if any user control code which has additional features of listview would help...

I am doing a feasibility study of using the listview in my app.
Functionality needed is to have thousands of records listed and sort by multiple numeric, string columns. Let me know of a native grid/table like control.
Thanks for your help....
0
Comment
Question by:rajaloysious
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9626675
You can sort the ListView using you own Comparer to sort the numeric items:


Public Class MyComparer
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As
Object) As Integer Implements IComparer.Compare

Dim itmX, itmY As ListViewItem
Dim valueX, valueY As Integer

itmX = CType(x, ListViewItem)
itmY = CType(y, ListViewItem)

valueX = CType(itmX.SubItems(1).Text, Integer)
valueY = CType(itmY.SubItems(1).Text, Integer)

If valueX < valueY Then
Return -1
ElseIf valueX = valueY Then
Return 0
Else
Return 1
End If

End Function

End Class
-------------------------------------------------

Add a buttom on your form and put the following code into
it:-

ListView1.ListViewItemSorter = New MyComparer()
ListView1.Sorting = SortOrder.Descending
ListView1.Sort()
0
 
LVL 8

Author Comment

by:rajaloysious
ID: 9626736
thanks for ur reply...But...as i have asked... how to do this for multiple columns
the sort columns may be like this string,numeric,string OR numeric,numeric,string and string and is more importantly dynamically selected by the user- As we do it in Outlook - using the shift and then clicking the column headers - sorting by multiple columns and that too dynamically
i guess i shd not use listview or would end up writing complex code myself for such an familiar feature?? - shouldnt this be straight forward...
help please...
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 9626761
Sorry, missed the "multiple part".  I'm a little tired this Monday morning, and I'm not fully awake.

If you are looking for a grid control, we use the VsFlexGrid.Net from ComponentOne.  It has the ability to sort on multiple columns with mixed sorting criteria.  We have used this control since the VB6 days, and I feel like it is head and shoulders above the DataGrid in VB6 and VB.NET.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show/Hide ASP.NET controls with JQuery best practices 3 47
compare between entities in entity framework 8 72
.NET 2008 VB and C# 6 27
C# Gridview 1 32
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question