Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Not able to add Item in Combo Box [modified]

Not able to add Item in Combo Box [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
comhelp
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G GauranG Shah

    Hi, When I use the above code in some Button even then I am getting Error code as 5. I.e. case WM_COMMAND: if (LOWORD(wParam) == IDOK) { SendMessage(GetDlgItem(hWndDlg,IDC_COMBO1),(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)L"ValueName"); dError = GetLastError(); //dError = 5; which mean Access denied }

    [ Screen Capture ][ Tool Tip ]

    N Offline
    N Offline
    Nishad S
    wrote on last edited by
    #7

    I have tried it. It is working fine... :( What is the return value of the SendMessage?

    - NS -

    G 1 Reply Last reply
    0
    • N Nishad S

      I have tried it. It is working fine... :( What is the return value of the SendMessage?

      - NS -

      G Offline
      G Offline
      GauranG Shah
      wrote on last edited by
      #8

      I am using this code in Modeless Dialog Box. Can it be the source of problem ? This is what I am getting.

      lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr ==0
      dError = GetLastError(); // dError == 1460
      lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); // l2 == 0
      dError = GetLastError(); // dError == 1460
      lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr == 0
      dError = GetLastError(); // dError == 1460
      lr= SendMessage(hCombo,(UINT)CB_GETCOUNT,(WPARAM)0,(LPARAM)0); //lr == 3
      dError = GetLastError(); // dError == 1460

      [ Screen Capture ][ Tool Tip ]

      N R 2 Replies Last reply
      0
      • G GauranG Shah

        I am using this code in Modeless Dialog Box. Can it be the source of problem ? This is what I am getting.

        lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr ==0
        dError = GetLastError(); // dError == 1460
        lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); // l2 == 0
        dError = GetLastError(); // dError == 1460
        lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr == 0
        dError = GetLastError(); // dError == 1460
        lr= SendMessage(hCombo,(UINT)CB_GETCOUNT,(WPARAM)0,(LPARAM)0); //lr == 3
        dError = GetLastError(); // dError == 1460

        [ Screen Capture ][ Tool Tip ]

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #9

        I got the problem... :) CB_ADDSTRING has no effect on last error. Try like this and you will get the answer... SetLastError( 10 ); SendDlgItemMessage( hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)L"Apple" );

        - NS -

        G 1 Reply Last reply
        0
        • G GauranG Shah

          I am using this code in Modeless Dialog Box. Can it be the source of problem ? This is what I am getting.

          lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr ==0
          dError = GetLastError(); // dError == 1460
          lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); // l2 == 0
          dError = GetLastError(); // dError == 1460
          lr= SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName); //lr == 0
          dError = GetLastError(); // dError == 1460
          lr= SendMessage(hCombo,(UINT)CB_GETCOUNT,(WPARAM)0,(LPARAM)0); //lr == 3
          dError = GetLastError(); // dError == 1460

          [ Screen Capture ][ Tool Tip ]

          R Offline
          R Offline
          Roger Broomfield
          wrote on last edited by
          #10

          CB_ADDSTRING returns the index of the item added, or CB_ERR ( = -1) if an error occurs, CB_ERRSPACE if insufficient space available. You add 3 items of the same value, each time the return value is 0, this is totally consistent with a combobox that has the CBS_SORT style. Furthermore the CB_GETCOUNT return value is 3 indicating that 3 items were infact added. Also there is no indication in the documentation of CB_ADDSTRING that it calls SetLastError() when an error occurs.

          1 Reply Last reply
          0
          • N Nishad S

            I got the problem... :) CB_ADDSTRING has no effect on last error. Try like this and you will get the answer... SetLastError( 10 ); SendDlgItemMessage( hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)L"Apple" );

            - NS -

            G Offline
            G Offline
            GauranG Shah
            wrote on last edited by
            #11

            Thnx Again. But its NOT working. I tried you code in WM_INITDIALOG and in Button even also. But its not showing anything in the combo box.

            [ Screen Capture ][ Tool Tip ]

            N G 2 Replies Last reply
            0
            • G GauranG Shah

              Thnx Again. But its NOT working. I tried you code in WM_INITDIALOG and in Button even also. But its not showing anything in the combo box.

              [ Screen Capture ][ Tool Tip ]

              G Offline
              G Offline
              GauranG Shah
              wrote on last edited by
              #12

              sorry for my post. It was happpening due to the silly mistake. the hight of the comobox was too small to show the charcters in it. I just take the new combo box with greater hight and problem solved. Thnx a lot for your help

              [ Screen Capture ][ Tool Tip ]

              N H 2 Replies Last reply
              0
              • G GauranG Shah

                Thnx Again. But its NOT working. I tried you code in WM_INITDIALOG and in Button even also. But its not showing anything in the combo box.

                [ Screen Capture ][ Tool Tip ]

                N Offline
                N Offline
                Nishad S
                wrote on last edited by
                #13

                :sigh: But the return value is the indication of success and again the count is correct as per your previous post... What kind of combobox is that? Can you check your code by doing as follows? 1. Add some items to combobox and through the resource editor 2. Comment out the dynamic item adding (CB_ADDSTRING) codes 3. Run the application and test it

                - NS -

                1 Reply Last reply
                0
                • G GauranG Shah

                  sorry for my post. It was happpening due to the silly mistake. the hight of the comobox was too small to show the charcters in it. I just take the new combo box with greater hight and problem solved. Thnx a lot for your help

                  [ Screen Capture ][ Tool Tip ]

                  N Offline
                  N Offline
                  Nishad S
                  wrote on last edited by
                  #14

                  :-D OK... kindly ignore my next solution... ha ha... ;)

                  - NS -

                  1 Reply Last reply
                  0
                  • G GauranG Shah

                    Hello Friends, I am using WIN32 Dialog based Application. And in that I am using combo box. But not able to add the string in the combo box. the Code I use to set the text in dialog box in as follows

                    case WM_INITDIALOG:
                    TCHAR *ValueName = new TCHAR[20];
                    wcscpy(ValueName,L"Gaurang ");
                    hCombo = GetDlgItem(hWndDlg,IDC_COMBO1);
                    SendDlgItemMessage(hWndDlg,IDC_COMBO1,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)L"Gaurang");
                    dError = GetLastError(); //dError = 1460
                    LRESULT lr = SendMessage(hCombo,(UINT)CB_ADDSTRING,(WPARAM)0,(LPARAM)L"ValueName");
                    dError = GetLastError(); //dError = 1460
                    break;

                    When I use the above line of code to set the Text in combo box it gives me the 1460 error code which says "This operation returned because the timeout period expired" -- modified at 6:55 Monday 29th October, 2007

                    [ Screen Capture ][ Tool Tip ]

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #15

                    Your code is working for me how did you make combobox can you show that code?

                    1 Reply Last reply
                    0
                    • G GauranG Shah

                      sorry for my post. It was happpening due to the silly mistake. the hight of the comobox was too small to show the charcters in it. I just take the new combo box with greater hight and problem solved. Thnx a lot for your help

                      [ Screen Capture ][ Tool Tip ]

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #16

                      Wow so your problem wasnt combobbox and your answer was MoveWindow :-D

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups