I am trying to associate some numerical values to the elements of a combobox using
the message CB_SETITEMDATA with no results (see the simple piece of code below).
$include "windows.inc"
CONST xCOMBO = 1
CONST xEDIT = 2
window w1
uint nItem
openwindow w1,0,0,422,126,@sysmenu,0,"Test",&whndl
SETWINDOWCOLOR w1,_GetSysColor(15)
CONTROL w1,@COMBOBOX,"",15,22,182,83,0x50800642,xCOMBO
CONTROL w1,@EDIT,"",239,22,142,27,0x50800000,xEDIT
FillCombo(w1)
WAITUNTIL w1 = 0
END
SUB whndl
select @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
case @IDCLOSEWINDOW
CLOSEWINDOW w1
case @IDCONTROL
SELECT @CONTROLID
case xCOMBO
IF @NOTIFYCODE = @CBNSELCHANGE
niItem = SENDMESSAGE(w1, CB_GETITEMDATA, GETSELECTED(w1,xCOMBO),0,xCOMBO)
SETCONTROLTEXT w1, xEDIT, str$(niItem)
end if
end select
END select
RETURN
ENDSUB
sub FillCombo(w:window)
uint pos,check
if controlexists(w,xCOMBO) then
ADDSTRING w, xCOMBO, "One"
ADDSTRING w, xCOMBO, "Two"
ADDSTRING w, xCOMBO, "Three"
ADDSTRING w, xCOMBO, "Four"
ADDSTRING w, xCOMBO, "Five"
for pos = 0 to 4
check = SENDMESSAGE(w, CB_SETITEMDATA, pos, pos+1 ,xCOMBO)
next pos
SETSELECTED w,xCOMBO,0
end if
end sub
Can anyone say me where I'm wrong?
Thanks!
Sergio
Not sure what you see wrong.
When I see "Three" in the combo box, I see "3" in the edit box
When I see "Five" in the combo box, I see "5" in the edit box
and so on.
I agree with Mike.
Yes, you you are right; I apologize for my absent-mindedness...
In my original code I've not included in the SENDMESSAGE( ..., CB_GETITEMDATA,...) row, the comobox control id (that I have instead inserted during the cut&paste of the example above...)
Now all works fine
Many thanks
bye
Sergio