Repost: Listview control sorting

  • Thread starter Thread starter Richard Krupa
  • Start date Start date
R

Richard Krupa

Hi Guys,

Ive tried posting this question to the ActiveX mail list a number of time
and have had no repsonse.

Does the listview control see all numbers as text? when i sort my listview
on a field that has numbers it does not sort them by:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 etc...

it sorts them like:

1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 3 4 5 6 7 8 9

how can i get it to sort properly? Ive tried adding the numbers to the
listbox using CLng(1) etc... and using format but it does not seem to make
any difference.

Any help would be appreciated!
 
Richard,
It appears as though this field, which contains what appears to be all
numbers, is really a text field. Check your field definition in your table
design.
However, I think Val(YourFieldName) in the query behind your listbox
should give you the numeric sorting you want.
 
Ta Al except the data is not comming from a table, i add it manually when
the item is added to the listview.

Set itmX = Forms!RegisterForm!ListViewTrans.ListItems.Add(, , RecViewCount)

RecViewCount is declared as integer and is increased by one when an item is
added. I want to sort the list view in desc order based on this field but i
get the problem i stated earlier.

Regards,
Richard
 
Hi Richard,
Sorry, I should have mentioned that with Access 97, you have yet an
extra step to go through!!
That's because it doesn't support the 'AddressOf' operator.

So, if you're still game to try it, go to this site:
http://64.38.171.38/lang/1033/codes.asp?ItemID=19#19

and download the CallBacks.xls sample.
Inside you'll find a module, basAddrOf.
Import that module into your db.

Now in the vb code, in the ListView1_ColumnClick event,
replace this:
ListView1.Sorted = False
SendMessage ListView1.hWnd, _
LVM_SORTITEMS, _
ListView1.hWnd, _
ByVal FARPROC(AddressOf CompareValues)

with this:


ListView1.Sorted = False
SendMessage ListView1.hWnd, _
LVM_SORTITEMS, _
ListView1.hWnd, _
ByVal FARPROC(AddrOf CompareValues)

You may crash if you try to go into Debug mode, so be careful.
 
Hey dan,

I tired that, ive used the addressof before in the past so i was awear of
it, however it complains about this line of code:

SendMessage ListView1.hWnd, _
LVM_SORTITEMS, _
ListView1.hWnd, _
ByVal FARPROC(AddrOf CompareValues)

Says:

Compile Error: Expected: list or seperator )

Also whats a picturebox ?

That demo uses it to output the results to, ive code it out cause i dont
need to display the results, just want the listview to sort correctly, but i
was just curious :)

Thanks

Regards,
Richard
 
Hi,
Okay, my fault. I took a closer look a the example call in the spreadsheet.
Try:
SendMessage ListView1.hWnd, _
LVM_SORTITEMS, _
ListView1.hWnd, _
ByVal FARPROC(AddrOf "CompareValues")

OR
ByVal FARPROC(AddrOf ("CompareValues"))

one of them should work!
 
Hey dan,

Ok well

SendMessage ListView1.hWnd, _
LVM_SORTITEMS, _
ListView1.hWnd, _
ByVal FARPROC(AddrOf("CompareValues"))

worked in the sense that it does not go red and u can compile the module
however when i execute the code i get:

Compile error: Expected Variable or procedure, not module

Regards,
Richard
 
Hi Richard,
That usually happens when you name a module the same name as
a function within the module. So if you named your module AddrOf,
and then called the function AddrOf, you would get that error.
 
Back
Top