Adding combo boxes to a list view
teps to achieve this:
-
Create a class derived from CListCtrl or CListView.
-
Subclass your view or control window using new class.
-
Create combo box with desired style (not visible - hence, do not use WS_VISIBLE).
-
Get list view control font and assign it to the created combo.
-
Handle NM_CLICK notification.
-
Use GetItemIndexRect to get cell’s rectangle using item and subitem retrieved from NMITEMACTIVATE (cast NMHDR pointer).
-
Set combo position over a cell and make combo visible.
-
Handle CBN_SELCHANGE notification from a combo box mapping WM_COMMAND using ON_CBN_SELCHANGE macro. You can also use OnCmdMsg or OnCommand virtual overrides.
-
In CBN_SELCHANGE notification handler, retrieve selected item’s string.
-
Get combo’s window rectangle and convert to client coordinates. Get center point from rectangle and call Hittest to determine cell a combo is over.
-
Using item and subitem returned from a Hittest set string and/or item data for the appropriate item of the list view control.
-
Hide combo box.
-
You can change a font size to fit combo box exactly into a cell height, or adjust a cells height to achieve the same.
You can populate combo each time with data appropriate for the cell combo will cover.