I want to add some data to the items of a combobox.
I use:
[code]
SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM)num, (LPARAM)i);
[/code]
where num is the index of the item and i is a value I want to attach to it.
This seems not to work, because when I use CB_GETITEMDATA I always obtain 0, everything I put in i.
Pheraphs I have to set some combo-box style to use user data??? (it's a normal combo-box, no owner-drawn or things like that).
nICO
[hr]
[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
JOHN KEATS
Comments
Show us some code.
: I want to add some data to the items of a combobox.
:
: I use:
:
: [code]
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM)num, (LPARAM)i);
: [/code]
:
: where num is the index of the item and i is a value I want to attach to it.
:
: This seems not to work, because when I use CB_GETITEMDATA I always obtain 0, everything I put in i.
:
: Pheraphs I have to set some combo-box style to use user data??? (it's a normal combo-box, no owner-drawn or things like that).
:
: nICO
:
: [hr]
: [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
: JOHN KEATS
:
:
: It should work fine. You dont need to set any styles.
:
: Show us some code.
:
There's not much to show... here it is:
[code]
SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0);
SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);
SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);
sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
// sel should be 5, but it is 0... I cannot understand why.
[/code]
[hr]
[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
JOHN KEATS
: [code]
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
: int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0)[red][b]-1[/b][/red];
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);
:
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);
:
: sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
: // sel should be 5, but it is 0... I cannot understand why.
: [/code]
:
: [hr]
: [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
: JOHN KEATS
:
:
[hr]
[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
JOHN KEATS
: : [code]
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
: : int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0)[red][b]-1[/b][/red];
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);
: :
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);
: :
: : sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
: : // sel should be 5, but it is 0... I cannot understand why.
: : [/code]
: :
: : [hr]
: : [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
: : JOHN KEATS
: :
: :
:
:
: [hr]
: [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
: JOHN KEATS
:
:
:
[blue]This will work only on combo-lists which are not sortable, but sortable list items will contain incorrect values. The better way to do it is to use the index returned by CB_ADDSTRING message and use it as WPARAM inside CB_SETITEMDATA. It is also faster, because you do not need the CB_GETCOUNT now. This technique also applies to a list box.[/blue]