Page Selection-list with item-data shows how and when to use itemdata with a selection list. The same works for a combo-box, except the message constants are different.
Let's skip the background info and go right to the source:
{windows.i} PROCEDURE AddComboItem : /*------------------------------------------------------------------------------ Purpose: add an item to the combo-box. Each item can be associated with itemdata (is low-level implementation of PRIVATE-DATA). ------------------------------------------------------------------------------*/ DEFINE INPUT PARAMETER ip_hCombobox AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER ip_ItemText AS CHARACTER NO-UNDO. DEFINE INPUT PARAMETER ip_ItemData AS INTEGER NO-UNDO. DEFINE VARIABLE lpString AS MEMPTR NO-UNDO. DEFINE VARIABLE SelIndex AS INTEGER NO-UNDO. DEFINE VARIABLE retval AS INTEGER NO-UNDO. SET-SIZE(lpString) = 0. SET-SIZE(lpString) = LENGTH(ip_ItemText) + 1. PUT-STRING(lpString,1) = ip_ItemText. RUN SendMessageA IN hpAPi (ip_hCombobox:HWND, 323, /* = CB_ADSTRING */ 0, GET-POINTER-VALUE(lpString), OUTPUT selIndex). RUN SendMessageA IN hpApi (ip_hCombobox:HWND IN FRAME frame-tools , 337, /* = CB_SETITEMDATA */ SelIndex, ip_ItemData, OUTPUT retval). SET-SIZE(lpString)=0. RETURN. END PROCEDURE.
The first call to SendMessage adds a text to the combo-box, so it does the same as combo-1:ADD-LAST(ip_ItemText). However it also returns a SelIndex, which is the unique and constant index number for the new combo item. This SelIndex is used in the second call to SendMessage.
The second call to SendMessage adds an integer data value to the combo-item.
{windows.i} ON VALUE-CHANGED OF COMBO-1 IN FRAME FRAME-tools /* Procedure */ DO: DEFINE VARIABLE SelIndex AS INTEGER NO-UNDO. DEFINE VARIABLE ItemData AS INTEGER NO-UNDO. RUN SendMessageA (combo-1:HWND, 327, /* = CB_GETCURSEL */ 0, 0, OUTPUT SelIndex). RUN SendMessageA (combo-1:HWND, 336, /* = CB_GETITEMDATA */ SelIndex, 0, OUTPUT ItemData). RUN Whatever(ItemData). END.
Normally I would prefer to use the Progress 9 feature of ITEM-DATA-PAIRS instead of this API solution. But ITEM-DATA-PAIRS are designed to work only if the screen-values are unique!