Thread: Adding Items to Combo Boxes

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    Question Items not appearing in combo or list box

    Hi,

    I'm currently trying to create a simple combo box, with a couple of entries that I add in the WM_INITDIALOG bit of the dialog handler. But when the dialog is displayed, the text items don't appear. BUT, when I click on the blank drop down box, the item appears in the associated edit box! Does anyone have any ideas what's going on?!

    Cheers!
    Last edited by tenthirty; 12-20-2001 at 06:26 AM.

  2. #2
    Hi,

    you can add Items to your combo box and then you have to select one and that one will apear in the edit box as default value
    Code:
    char text[50];
    for(int i=0;i<10;i++)
    {
    sprintf(text,"nr %i",i);
    SendDlgItemMessage(hDlg,IDC_COMBO,CB_ADDSTRING,0,(LPARAM)text);
    }
    SendDlgItemMessage(hDlg,IDC_COMBO,CB_SELECTSTRING,-1,(LPARAM)"nr 1");
    I hope this is what you are looking for. I have to admit, I haven't tested the code. So it is possible that it won't work

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    Thanks maes,

    Sorry though, that's not quite the problem I've got, even after I've put entries into the list, when I run the routine they simply don't appear in the list, the same is happening if I change the combo box to a list box, no entries appear in the list!

    Any ideas anyone?

  4. #4
    Sorry for the wrong anwser, I misundestood you

    can you post the code you use in your dialogbox. So I (or someone else) can test it.

    thx

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    Okay, here we go! Code is as follows:

    Code:
    	SendDlgItemMessage (hDlg,IDC_HEADINGS,CB_RESETCONTENT,0,0);
    	currEvent_p = firstEvent_p;
    	while (currEvent_p != NULL)
    	{
    		SendDlgItemMessage(hDlg,
    				   IDC_HEADINGS,
    				   CB_ADDSTRING,
    				   0,
    				   (LPARAM)currEvent_p->heading);
    		currEvent_p = currEvent_p->nextEvent_p;
    	}
    Nothing else apart from the original 'DialogBox()', and I really can't see anything wrong with this bit. Is it possible for some reason the font colour has set itself to white? That's the only thing I can think of!

    Cheers!

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    and some more info:

    That bit DOES work, I've put a message box afterwards that displays the number of items in the list, and it gives the correct number. So the items are in the list, they are just not getting shown. Are there any properties that I should set / unset?

    onwards and upwards then!

  7. #7
    I think your code is corect. I don't think it is the color, you have to use WM_CTLCOLORSTATIC for that. and when you select an option, you should be able to see it anyway, even when it is white. If you are using msvc++ you can try to put a breakpoint at the SendDlgItemMessage and see what the value of currEvent_p->heading is. or you can output them to a file. I assume it is an array of char, or something like that.

    I'm sorry, this is the only thing I can come up with

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    Cheers,

    am all out of ideas, so I think it may well be a case of delete all and start again,
    thanks for the time!

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> of delete all and start again

    Sometimes best, but not always. Are you sure for example, (check for typo's), that silly things like your hDlg is valid?

    Another silly thought, is your box big enough to show your lines?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Make sure it is not set to OWNER DRAW or if so has the HAS STRINGS set and you are handling the paint.

    If made in the resource editor make sure is VISIBLE.

    Try removing the pointer to the string and try

    Code:
    SendDlgItemMessage(hDlg, IDC_HEADINGS, CB_ADDSTRING,(WPARAM) 0, (LPARAM)"Some Text");
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    Talking Success!

    Hurrah!

    Yeah, that's it. I had the box set to OWNER_DRAW and yes, I did have HAS_STRINGS set, but I changed the OWNER_DRAW to No, and then it all started working.

    Who knows, who cares! Happy Christmas everyone!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  4. Help with Combo Boxes Please
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 07-26-2002, 06:48 PM
  5. Help With Combo Boxes
    By Daniel in forum Windows Programming
    Replies: 1
    Last Post: 05-25-2002, 07:53 PM