Listview

From Team Developer SqlWindows Wiki
Jump to: navigation, search

VT ListView control


Contents


Pointer2.png cListView: keep selected item highlighted Pointer.png

When selecting an item in cListView it is getting a bounded selection background color.
But when the listview is loosing focus, this selection color is changed to a less visible color. The item is still selected though.


See the image below which shows two listview objects.
Both listviews have an item selected. The datafield in the middle has the current focus.
The listview at the left has the default behavior. The selected item is not clearly visible.
The listview at the right shows a workaround to keep the item visually selected.


ListViewKeepItemFocus.png


The cListView object is a wrapper around the "SysListView32" WinApi control.
So how the items are displayed is managed by this default control and shows also in other Windows applications the issue
with the item selection color.


The workaround to keep the item visually selected even when the listview does not have the focus is this:


When the control receives WM_KILLFOCUS, it should return 0 (zero) to suppress the "unhighlighting" of the current selection.
It is not possible to implement this trick on listviews in TD without some extra work.
The cListView class is not the real listview object but a wrapper. The real object is a child of the cListView object.
So defining messages under the cListView object in the TD outline will not be triggered.
This means that we are unable to code the WM_KILLFOCUS message.


We can however implement it using SubClasser.
By subclassing the real listview control and fetch the WM_KILLFOCUS message, we can implement the message at cListView level.

On SAM_Create
   Call RegSubclass( GetWindow( hWndItem, GW_CHILD ), WM_KILLFOCUS, hWndItem, PAM_KillFocus, SUBCLASS_FLAG_INSTEAD )
On PAM_KillFocus
   !
   ! Selected item of the listview will still be highlighted when losing focus
   Return 0
On SAM_Destroy
	Call UnregSubclass( GetWindow( hWndItem, GW_CHILD ), WM_KILLFOCUS)


On create of the cListView object the WM_KILLFOCUS of the SysListView32 child object is subclassed so that it is send
to the cListView object as a custom message : PAM_KillFocus
Then this custom message is defined to return 0 (zero).
On destruction of the object, the subclassing is removed.


Here you can download a sample:
Down.png WIKI_ListView_KeepFocus.zip