Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView Sorting 2

Status
Not open for further replies.

ZmrAbdulla

Technical User
Apr 22, 2003
4,364
AE
Hi,
Can anyone show me an easy way to sort columns in LstView.
(not Listbox). Found many in the VB section but I am unable to use them in access effectively.

thanks

Zameer Abdulla
 
Can you not control the sorting via the underlying query, re-querying if necessary?

 
Mike,
I think I was not clear on my question.
What I need is to sort the Listview by clicking on the Column Header. So when you click on the header it will sort the columns in Alphabetic, Numeric, By Date, etc.. Similar to sort in the datasheet view.
Thanks

Zameer Abdulla
 
In Access you can do a similar thing to what you are trying to do with your VB control.

Either with a data sheet grid or a listbox to display the data, just put a command button above each column. Connect each button to an action which rebuilds the source query. This is very quick to do.

 
Mike,
As far as my concern, ListView (Report style) is the best one to be used to display the records to make the application a professional looking one.

ListBox has many good properties that are easy to use and the worst is you can't align the data left, right or middle that ListView allows. ListView6 has a property that allows drawing a line (gridline) between the records and not in ListBox.
I have a sample that is using a listbox with command button to sort the listbox that is not bad.

Talking about datagrid (Activex) is not so easy to populate with the data

Datasheet has all those entire good abilities with only drawback. The empty portion of the datasheet will be grey in color leaving a BIG HOLE in the form.

Continues forms are another way. Listview columns are easy to resize in the runtime. That gives you a freedom to populate different tables’ data in a single ListView one after another that makes your application smaller.

These are the reasons that I prefer ListView. I think I have described well.



Zameer Abdulla
 
Hi,
Here is the answer to sort listview in access. Still I have to do it for date this code is sorting alpha & Numeric values

Code:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As Object)
' When a ColumnHeader object is clicked, the ListView control is
' sorted by the subitems of that column.
' Set the SortKey to the Index of the ColumnHeader - 1
Me.ListView1.SortKey = ColumnHeader.Index - 1
' Set Sorted to True to sort the list.
 If ListView1.SortOrder = lvwAscending Then
            ListView1.SortOrder = lvwDescending
        Else
            ListView1.SortOrder = lvwAscending
        End If
Me.ListView1.Sorted = True

End Sub
The difference in VB is below
Code:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
                                    MSComctlLib.ColumnHeader)
'Your code===
End Sub



Zameer Abdulla
 
I seem to be following you around Zameer! Did you find out how to sort columns by date?

Thanks
 
It is because there are a few thread discussing ListView in these forums.
Sorting by date was one of my concern. It is not possible with Microsoft ListView Control as it is. But there is a work around add another column with the data of date and column width Zero & format "yyyy-mm-dd", then once you click on the header of the date column you ask listview to sort the hidden column. It was a pain. I didn't do that. If you have VB6 then Planet Source Code have some samples to show you how to do.
Google-Groups also a place to search for that. I will come back if I find any good one
Here is a free activex control called extended listview control.You can't forget it once you use. Don't worry about sorting coloring etc...
Regards


Zameer Abdulla
Visit Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top