?
Solved

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

Posted on 2003-10-27
3
Medium Priority
?
421 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 1500 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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