Solved

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

Posted on 2003-10-27
3
345 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 109
Paging GridView 7 32
Check if number is currency 15 28
Round a string to two digits 12 23
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.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

10 Experts available now in Live!

Get 1:1 Help Now