Hi Everyone!

I have a ListView control displaying data from a database. The Primay Key
of the table is set as "Key" in the ListView control.

It is known that a ListView control sorts data by setting the SortKey and
Sorted properties, always in a "text" fashion. The following MSDN KB articles
explains how to sort data when the column contains DATE data using the LVM_SORTITEM
message and custom compare function.

KB: Q170884. HOWTO: Sort a ListView Control by Date

Howver, once I sort the listview the relationship between the "Index" and
the "Key" is out of sync. I was looking for a way to get the "KEY" for the
selected item. If I use the normal sorting I could simply get it using:


If the listview control is sorted by sending LVM_SORTITEM message, however,
the returned key might from a different row.

The solution I have got so far working is by storing the Key as a hiden column,
geting the Index of the Selected Item and retrieving the text of the hiden
key column, all by sending LVM_xxxx messages. Even to delete the current

Has anyone has solved this problem in a simpler way from VB???

I appreciate your time for reading this and sharing your experience on this

Birhanu Digafe
Software Engineer, MCP
BizSoft PLC