Solved

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

Posted on 2003-10-27
3
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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