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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Combo Box and Edit Box

Combo Box and Edit Box

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
12 Posts 3 Posters 1 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.
  • E Offline
    E Offline
    Eversman
    wrote on last edited by
    #1

    Hey, I am using Visual C++, and I created a Combo Box and added the options into it. Now, when someone selects one of the options, I want a text describing the option to appear in an edit box. I have looked around and only found a few things, but nothing really helped. Thanks for the help

    A 1 Reply Last reply
    0
    • E Eversman

      Hey, I am using Visual C++, and I created a Combo Box and added the options into it. Now, when someone selects one of the options, I want a text describing the option to appear in an edit box. I have looked around and only found a few things, but nothing really helped. Thanks for the help

      A Offline
      A Offline
      alex barylski
      wrote on last edited by
      #2

      The combox by default displays the text in the list control in the edit box as each item is selected. I'm not sure, but you could maybe try capturing ON_CBN_EDITUPDATE or ON_CBN_SELCHANGE and then forcing the edit to change it's value. This approach won't work if the drop down list and edit field are dual synchronized. What I mean by this is if you set the edit content it make force a new item to be selected inside the list box as well and visa-versa. If this is the case you will have to subclass the CComboBox control and override this functionality. Cheers :) How do I print my voice mail?

      E 1 Reply Last reply
      0
      • A alex barylski

        The combox by default displays the text in the list control in the edit box as each item is selected. I'm not sure, but you could maybe try capturing ON_CBN_EDITUPDATE or ON_CBN_SELCHANGE and then forcing the edit to change it's value. This approach won't work if the drop down list and edit field are dual synchronized. What I mean by this is if you set the edit content it make force a new item to be selected inside the list box as well and visa-versa. If this is the case you will have to subclass the CComboBox control and override this functionality. Cheers :) How do I print my voice mail?

        E Offline
        E Offline
        Eversman
        wrote on last edited by
        #3

        I tried doing that, didn't work, here is my code. void CDEPDlg::OnSelchangeCombo1() { // TODO: Add your control notification handler code here UpdateData(true); if(m_type1=="Run #1") { m_purp1="Test"; } UpdateData(false); } m_type1 is the combo box, and Run #1 is the option in the combo box. m_purp1 is the edit box that i want it to display the description. I know it is wrong, so criticize all you want, just need help with it. Thanks

        A M 2 Replies Last reply
        0
        • E Eversman

          I tried doing that, didn't work, here is my code. void CDEPDlg::OnSelchangeCombo1() { // TODO: Add your control notification handler code here UpdateData(true); if(m_type1=="Run #1") { m_purp1="Test"; } UpdateData(false); } m_type1 is the combo box, and Run #1 is the option in the combo box. m_purp1 is the edit box that i want it to display the description. I know it is wrong, so criticize all you want, just need help with it. Thanks

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          It's been a while since I subclassed comboboxes or dealt with them for that matter :) How did you get m_purp1and m_type1 to map to the 2 controls that make up an CComboBox? How do I print my voice mail?

          E 1 Reply Last reply
          0
          • A alex barylski

            It's been a while since I subclassed comboboxes or dealt with them for that matter :) How did you get m_purp1and m_type1 to map to the 2 controls that make up an CComboBox? How do I print my voice mail?

            E Offline
            E Offline
            Eversman
            wrote on last edited by
            #5

            I went to the class wizard and did it there. m_type1 is a CString and m_purp1 is a CString also

            1 Reply Last reply
            0
            • E Eversman

              I tried doing that, didn't work, here is my code. void CDEPDlg::OnSelchangeCombo1() { // TODO: Add your control notification handler code here UpdateData(true); if(m_type1=="Run #1") { m_purp1="Test"; } UpdateData(false); } m_type1 is the combo box, and Run #1 is the option in the combo box. m_purp1 is the edit box that i want it to display the description. I know it is wrong, so criticize all you want, just need help with it. Thanks

              M Offline
              M Offline
              monrobot13
              wrote on last edited by
              #6

              If you're wanting to update an Edit Box that isn't the one at the top of the Combo Box (which is what it looks like) try this

              void CDEPDlg::OnSelchangeCombo1()
              {
              CString text;
              m_type1.GetWindowText (&text);
              if(text == "Run #1")
              m_purp1.SetWindowText("Test");

              }

              - Aaron

              E 1 Reply Last reply
              0
              • M monrobot13

                If you're wanting to update an Edit Box that isn't the one at the top of the Combo Box (which is what it looks like) try this

                void CDEPDlg::OnSelchangeCombo1()
                {
                CString text;
                m_type1.GetWindowText (&text);
                if(text == "Run #1")
                m_purp1.SetWindowText("Test");

                }

                - Aaron

                E Offline
                E Offline
                Eversman
                wrote on last edited by
                #7

                Thanks for the help. I am getting this error, C:\DEP\DEPDlg.cpp(182) : error C2664: 'void __thiscall CWnd::GetWindowTextA(class CString &) const' : cannot convert parameter 1 from 'class CString *' to 'class CString &' A reference that is not to 'const' cannot be bound to a non-lvalue

                E 1 Reply Last reply
                0
                • E Eversman

                  Thanks for the help. I am getting this error, C:\DEP\DEPDlg.cpp(182) : error C2664: 'void __thiscall CWnd::GetWindowTextA(class CString &) const' : cannot convert parameter 1 from 'class CString *' to 'class CString &' A reference that is not to 'const' cannot be bound to a non-lvalue

                  E Offline
                  E Offline
                  Eversman
                  wrote on last edited by
                  #8

                  I took out the & in the (&text) and it worked, and it works, but i have to select the Run #1 twice for the Test to show up in the edit box. Thanks

                  M 1 Reply Last reply
                  0
                  • E Eversman

                    I took out the & in the (&text) and it worked, and it works, but i have to select the Run #1 twice for the Test to show up in the edit box. Thanks

                    M Offline
                    M Offline
                    monrobot13
                    wrote on last edited by
                    #9

                    but i have to select the Run #1 twice for the Test to show up in the edit box Try chaging your message from CBN_SELCHANGE to CBN_SELENDOK. I think the reason you're having to select it twice is that CBN_SELCHANGE is sent before the selection changes, therefore the text, "Run #1" in your case, isn't actually in the edit portion when the message is processed. CBN_SELENDOK is sent after the selection is made. Just use class wizard to remove the selchange and add a selend - Aaron - Aaron

                    E 1 Reply Last reply
                    0
                    • M monrobot13

                      but i have to select the Run #1 twice for the Test to show up in the edit box Try chaging your message from CBN_SELCHANGE to CBN_SELENDOK. I think the reason you're having to select it twice is that CBN_SELCHANGE is sent before the selection changes, therefore the text, "Run #1" in your case, isn't actually in the edit portion when the message is processed. CBN_SELENDOK is sent after the selection is made. Just use class wizard to remove the selchange and add a selend - Aaron - Aaron

                      E Offline
                      E Offline
                      Eversman
                      wrote on last edited by
                      #10

                      Thanks for your help. I tried that and I still have to do it twice to get it to show up. Any more ideas?

                      M 1 Reply Last reply
                      0
                      • E Eversman

                        Thanks for your help. I tried that and I still have to do it twice to get it to show up. Any more ideas?

                        M Offline
                        M Offline
                        monrobot13
                        wrote on last edited by
                        #11

                        Figured that would work, guess not though. Try this

                        int cur = m_type1.GetCurSel ();
                        CString text;
                        m_type1.GetLBText (cur, text);
                        if (text == "Run #1")
                        m_purp1.SetWindowText ("Test");

                        - Aaron

                        E 1 Reply Last reply
                        0
                        • M monrobot13

                          Figured that would work, guess not though. Try this

                          int cur = m_type1.GetCurSel ();
                          CString text;
                          m_type1.GetLBText (cur, text);
                          if (text == "Run #1")
                          m_purp1.SetWindowText ("Test");

                          - Aaron

                          E Offline
                          E Offline
                          Eversman
                          wrote on last edited by
                          #12

                          Good to go, thanks buddy

                          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