Combo-box data... what am I missing ??? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Combo-box data... what am I missing ???

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

  • pingpongpingpong Posts: 937Member
    It should work fine. You dont need to set any styles.

    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
    :
    :

  • chick80chick80 Posts: 349Member
    [b][red]This message was edited by chick80 at 2003-11-16 6:9:21[/red][/b][hr]
    : 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

  • chick80chick80 Posts: 349Member
    Ok, I found the error myself... it was really a stupid thing.
    : [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


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : Ok, I found the error myself... it was really a stupid thing.
    : : [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]
Sign In or Register to comment.