Sorting numerically a ListView column

N

nartla

Hello,


I am working on an app developped in VBA/Access, and in a form, I use
a ListView control with several columns.
When I click on the top of the columns, the items are sorted
accordingly to the information stored in that column. My concern is
that this sort is made alphabetically, and one of my colums contains a
numerical ID, so when clicked, this column should be sorted
numerically (i.e 10 after 2) and not alphabetically (i.e 10 before 2).

Since I had nothing to do to have the alphabetical sort attached to
the columns of my ListView (in my code, I use myListView.Sorted =
False), I would like to know how I could alter this automatic sort to
make it numerical, just for one of the columns of the ListView ?


Thank you for your help !
 
D

Douglas J. Steele

Unfortunately, I believe all data in Listviews are converted to strings.

Take a look at what Randy Birch has at
http://vbnet.mvps.org/code/comctl/lvdemo3.htm, and at the bottom of
http://vbnet.mvps.org/code/comctl/lvdemo4.htm You should be able to use the
code from http://vbnet.mvps.org/code/callback/lvsortcallback.htm

Obligatory warning: Randy's site is aimed at VB programmers. There are some
significant differences in the controls available for forms in VB and in
Access. Consequently, not all of his examples will port directly to Access.
Since the listview control comes from an external OCX, though, I believe
that the listview-specific code should work without change.

Another alternative might be to use a continuous form as a subform rather
than the listview control.
 
A

Albert D. Kallal

What I would simply do is simply add another column to the SQL of that list
view.

I would then simply pad that column

eg:

format([fieldName],"0000000")

thus you'll get a format like


0000001
0000002

the spite the fact that this is the tax column, it will thus or correctly if
you pad zeroes in front.

So, the old sort on the actual number field column sort on a formatted
column that you've added to the query (I'm staying to add an extra column
because the code and other parts of the application actually might need a
real ID field without zeros in front).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top