Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using SendMessage with the LVM_SORTITEMSEX message.

151 views
Skip to first unread message

Fiona Curnow

unread,
Feb 8, 2002, 6:18:59 AM2/8/02
to
I am having problems with using the SendMessage API function when using the
LVM_SORTITEMSEX message.

I have successfully used the sendMessage function with the LVM_SORTITEMS
message, to sort the items on their text values, but now want to be able to
sort on their index values. I realise that I must be doing something wrong
whilst sending the new message, but can't work out what!

My code is as follows:

SendMessage lvwPins.hWnd, _
LVM_SORTITEMSEX, _
lvwPins.hWnd, _
ByVal SetAddress(AddressOf CompareIndices)

, where CompareIndicies is my sorting function.

Can anyone help?

Thanks,

Fiona


Aaron Robinson

unread,
Feb 8, 2002, 12:55:06 PM2/8/02
to
Fiona,

Without downloading it and playing with it, I think that Klaus H. Probst has a
working example in his CodeBox at http://www.vbbox.com/codebox/demos.htm

HTH,

- Aaron

Randy Birch

unread,
Feb 8, 2002, 9:07:59 PM2/8/02
to
The index value changes whenever the control is sorted ... there is no call
to restore the control to the initial unsorted view that I've ever seen. My
take on the LVM_SORTITEMSEX message is that its for the same purpose as
LVM_SORTITEMS, with the difference being the latter passes data, and the
former passes the current index to the data. Remember too that a sort of a
VB listview control by API does not sort the underlying collection the
control maintains of the listittems, therefore the listitem collection index
and the visual listitem index will not be the same.

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.

"Fiona Curnow" <fiona....@optionexist.co.uk> wrote in message
news:1013166920.12468....@news.demon.co.uk...

Brad Martinez

unread,
Feb 8, 2002, 9:45:38 PM2/8/02
to
Randy (and Fiona),

>The index value changes whenever the control is sorted ... there is no call
>to restore the control to the initial unsorted view that I've ever seen. My
>take on the LVM_SORTITEMSEX message is that its for the same purpose as
>LVM_SORTITEMS, with the difference being the latter passes data, and the
>former passes the current index to the data. Remember too that a sort of a
>VB listview control by API does not sort the underlying collection the
>control maintains of the listittems, therefore the listitem collection index
>and the visual listitem index will not be the same.

Nearest I can tell, this only applies to the Comctl32.ocx ListView...

When the Comctl32.ocx ListView's Sorted property is called, it sends
itself a LVM_SORTITEMS specifying the address of its internal sort
callback procedure that sorts ListItems only by text, as specified by
the ListView's SortOrder and SortKey properties, after which code in the
Sorted property reorders the indices of the sorted ListItems to represent
their new one-based position in the ListView. If LVM_SORTITEMS by
itself is sent to the ListView without the Sorted property being set to
True, ListItem index reordering doesn't happen.

OTOH, the Mscomctl.ocx ListView reorders its ListItem indices after
receipt and processing of LVM_SORTITEMS (i.e. the ListItem index
reordering happens even if the Sorted property is not set to True, probably
in the ListView's WndProc). One of the few things the control got right...

But its petty simple (yet not real obvious) to overcome this problem in
the Comctl32.ocx ListView. Subclass the ListView, and then just set its
Sorted property as would normally be done. When the ListView sends
a LVM_SORTITEMS to itself, intercept the message and replace the
ListView's internal sort procedure (the message's lParam value) with the
address of the user-defined sort procedure (ListViewCompareProc).

Here's a demo that does this, along with a bunch of other monkey
business: http://mvps.org/btmtz/listview/lvsortex.zip

--
Brad Martinez, http://www.mvps.org
Please direct questions/replies to the newsgroup


0 new messages