Solved

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

Posted on 2003-10-27
3
351 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

943 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now