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. Clearing the edit box in ccombobox

Clearing the edit box in ccombobox

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
38 Posts 3 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.
  • L lctrncs

    I do not have very much real estate in my database dialog. I like the idea of having a one line control open up to display a multiline area for the selection of records. If I went with the list control, I would need a much larger dialog and my users would have to fool around with scroll bars more.

    "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #17

    Would it be possible to break your dialog up into multiple pages and use a property sheet?


    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

    "Judge not by the eye but by the heart." - Native American Proverb

    L 1 Reply Last reply
    0
    • Z Zac Howland

      Following what I think you are trying to do, you are using the wrong control. ComboBoxes are designed to select an option and display it until the selection is changed. Clearing it goes against what it was designed for. You should either use a ListBox or a List Control for what I think you are trying to do.

      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      L Offline
      L Offline
      lctrncs
      wrote on last edited by
      #18

      Thanks for responding. I wish that a list box would meet my needs! There is not much real estate on my dialog so the drop down window is very attractive. In addition, the list of record data is only visible when you want to see it, making the dialog look better (less "busy" and confusing). If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?

      "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

      D 1 Reply Last reply
      0
      • D David Crow

        lctrncs wrote:

        How do you get a dropdown list edit box to immediately clear itself?

        m_cb.InsertString(0, "");
        m_cb.SetCurSel(0);


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        L Offline
        L Offline
        lctrncs
        wrote on last edited by
        #19

        I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem. Being a complete beginner, this is the first time I have tried to instantiate a class and my local resource (an embedded systems programmer) cannot provide much assistance. The class (CCombobox) and member (InsertString) I am using are overridden. When I instantiate an instance like this OverRiddenCombobox w_wndOverBox; locally in the function where I want to use it (along with w_wndOverBox InsertString(0,"",0) , my program compiles and runs fine until I try to open the dialog. Then I get and exception error, and the debuger shows me a line in afxwin.inl apparently defining the not overridden base class member InsertSting with two arguments (my InsertString has three arguments). Suggestions?

        "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

        D 1 Reply Last reply
        0
        • D David Crow

          Would it be possible to break your dialog up into multiple pages and use a property sheet?


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          L Offline
          L Offline
          lctrncs
          wrote on last edited by
          #20

          I suppose it would be possible. However, I am trying to keep things simple and user friendly.

          "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

          1 Reply Last reply
          0
          • L lctrncs

            I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem. Being a complete beginner, this is the first time I have tried to instantiate a class and my local resource (an embedded systems programmer) cannot provide much assistance. The class (CCombobox) and member (InsertString) I am using are overridden. When I instantiate an instance like this OverRiddenCombobox w_wndOverBox; locally in the function where I want to use it (along with w_wndOverBox InsertString(0,"",0) , my program compiles and runs fine until I try to open the dialog. Then I get and exception error, and the debuger shows me a line in afxwin.inl apparently defining the not overridden base class member InsertSting with two arguments (my InsertString has three arguments). Suggestions?

            "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #21

            lctrncs wrote:

            I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem.

            Use -> with pointers, and a . (dot) otherwise. The compiler should warn you of incorrect usage.

            lctrncs wrote:

            w_wndOverBox InsertString(0,"",0)

            What's holding w_wndOverBox and InsertString() apart?

            lctrncs wrote:

            Then I get and exception error, and the debuger shows me a line in afxwin.inl...

            An exception or an assertion?


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            L 1 Reply Last reply
            0
            • L lctrncs

              Thanks for responding. I wish that a list box would meet my needs! There is not much real estate on my dialog so the drop down window is very attractive. In addition, the list of record data is only visible when you want to see it, making the dialog look better (less "busy" and confusing). If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?

              "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #22

              lctrncs wrote:

              If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?

              To clear any "selected" text from the control. Are you selecting the text prior to calling the Clear() method?


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              L 1 Reply Last reply
              0
              • L lctrncs

                Thanks for all your help! However,

                DavidCrow wrote:

                m_cb.InsertString(0, "");m_cb.SetCurSel(0);

                appears to solve the clearing problem only for the Dropdown Style combobox (providing much more acceptable appearance), but sadly does not clear the edit box for the Drop List style. :confused: In drop list mode my OnSelchangeCombo function sends a WM_SETTEXT right before leaving the function and ignoring: ->InsertString(0,"",0); //(overridden InsertString) ->SetWindowText(""); ->SetDlgItemText( IDC_COMBO, "") even though it executes lines like: ->GetCurSel(); immediately before the ->InsertString etc. Subsequent attempts in my DisplayDialog function to clear the Drop List edit box employing the ->InsertString(0,"",0); //(overridden InsertString) ->SetWindowText(""); ->SetDlgItemText( IDC_COMBO, "") edit box are also unsuccessful. Could the Drop List style be refusing to allow me to change the edit box because I have the "Owner Draw" selection set to "No?" Thanks again for your assistance to date. I appreciate it a great deal.

                "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #23

                lctrncs wrote:

                In drop list mode my OnSelchangeCombo function...

                What does this method look like?


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                L 1 Reply Last reply
                0
                • D David Crow

                  lctrncs wrote:

                  I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem.

                  Use -> with pointers, and a . (dot) otherwise. The compiler should warn you of incorrect usage.

                  lctrncs wrote:

                  w_wndOverBox InsertString(0,"",0)

                  What's holding w_wndOverBox and InsertString() apart?

                  lctrncs wrote:

                  Then I get and exception error, and the debuger shows me a line in afxwin.inl...

                  An exception or an assertion?


                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                  "Judge not by the eye but by the heart." - Native American Proverb

                  L Offline
                  L Offline
                  lctrncs
                  wrote on last edited by
                  #24

                  DavidCrow wrote:

                  What's holding w_wndOverBox and InsertString() apart?

                  A dot operator (sorry about the incorrect post).

                  DavidCrow wrote:

                  An exception or an assertion?

                  An assertion: Debug Assertion Failed... _AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString) { ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }

                  "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                  D 1 Reply Last reply
                  0
                  • L lctrncs

                    DavidCrow wrote:

                    What's holding w_wndOverBox and InsertString() apart?

                    A dot operator (sorry about the incorrect post).

                    DavidCrow wrote:

                    An exception or an assertion?

                    An assertion: Debug Assertion Failed... _AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString) { ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }

                    "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #25

                    lctrncs wrote:

                    An assertion: Debug Assertion Failed... _AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString) { ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }

                    Which indicates you have a non-existent window. At what point are you trying to populate the combobox?


                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                    "Judge not by the eye but by the heart." - Native American Proverb

                    L 1 Reply Last reply
                    0
                    • D David Crow

                      lctrncs wrote:

                      If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?

                      To clear any "selected" text from the control. Are you selecting the text prior to calling the Clear() method?


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      L Offline
                      L Offline
                      lctrncs
                      wrote on last edited by
                      #26

                      Yes. I select the text with: pCombo->SetEditSel(0,-1); Interestingly, I have found that pCombo->SetEditSel(0,-1); pCombo->Clear(); does not work as well as pCombo->SetEditSel(0,-1); pCombo->Paste(); pCombo->SetEditSel(0,-1); pCombo->Clear(); while this is effective - it not cosmetically pleasing.

                      "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                      1 Reply Last reply
                      0
                      • D David Crow

                        lctrncs wrote:

                        An assertion: Debug Assertion Failed... _AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString) { ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }

                        Which indicates you have a non-existent window. At what point are you trying to populate the combobox?


                        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                        "Judge not by the eye but by the heart." - Native American Proverb

                        L Offline
                        L Offline
                        lctrncs
                        wrote on last edited by
                        #27

                        I populate the combobox in OnInitDialog - which is only called upon dialog start and after a change to the database such as adding or deleting a record. I am trying to clear the dropdown style edit box (drop list style would be preferred due to the static edit box) from my DisplayRecord function (called at the end of OnInitDialog), and this is where I have instantiated m_wndComboBox, and from where I call m_wndComboBox.InsertString(0,"",0). The control exists on a modeless dialog, which is trying to open at the time of the assert.

                        "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                        D 1 Reply Last reply
                        0
                        • L lctrncs

                          I populate the combobox in OnInitDialog - which is only called upon dialog start and after a change to the database such as adding or deleting a record. I am trying to clear the dropdown style edit box (drop list style would be preferred due to the static edit box) from my DisplayRecord function (called at the end of OnInitDialog), and this is where I have instantiated m_wndComboBox, and from where I call m_wndComboBox.InsertString(0,"",0). The control exists on a modeless dialog, which is trying to open at the time of the assert.

                          "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #28

                          lctrncs wrote:

                          ...this is where I have instantiated m_wndComboBox...

                          m_wndComboBox should be a member variable, not local to some function.


                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                          "Judge not by the eye but by the heart." - Native American Proverb

                          L 1 Reply Last reply
                          0
                          • D David Crow

                            lctrncs wrote:

                            In drop list mode my OnSelchangeCombo function...

                            What does this method look like?


                            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                            "Judge not by the eye but by the heart." - Native American Proverb

                            L Offline
                            L Offline
                            lctrncs
                            wrote on last edited by
                            #29

                            What does my OnSelChangeCombo function look like? It is rather simple: 1. Pointer to the Combobox with assert if NULL, 2. code to return index of selected item in listbox from control directed alpha listing (thank you Chris Losinger!), 3. dirtyflag check of record and associated commit if true, 4. call of the GotoRecord function.

                            "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                            D 1 Reply Last reply
                            0
                            • L lctrncs

                              What does my OnSelChangeCombo function look like? It is rather simple: 1. Pointer to the Combobox with assert if NULL, 2. code to return index of selected item in listbox from control directed alpha listing (thank you Chris Losinger!), 3. dirtyflag check of record and associated commit if true, 4. call of the GotoRecord function.

                              "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #30

                              Ok, what I have here may help, or it may not since it is not entirely like what you have. I have a CRecordset-derived class that reads from the Employees table of the Northwind database. I have a dialog with a combobox (having the CBS_DROPDOWNLIST style) and listbox. Selecting an item from the combobox will add it to the listbox. The selection in the combobox is then cleared.

                              BOOL CMyDlg::OnInitDialog()
                              {
                              CDialog::OnInitDialog();

                              CDatabase db;
                              CSet rs(&db);
                              
                              rs.Open();
                              while (! rs.IsEOF())
                              {
                                  m\_combo.AddString(rs.m\_LastName);
                                  rs.MoveNext();
                              }
                              
                              rs.Close();
                              
                              m\_combo.InsertString(0, "");
                               
                              return TRUE;  // return TRUE  unless you set the focus to a control
                              

                              }

                              void CMyDlg::OnSelchangeCombo1()
                              {
                              int nIndex = m_combo.GetCurSel();
                              CString strItem;
                              m_combo.GetLBText(nIndex, strItem);
                              m_list.AddString(strItem);

                              m\_combo.SetCurSel(0);
                              

                              }

                              Is this close?


                              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                              "Judge not by the eye but by the heart." - Native American Proverb

                              L 1 Reply Last reply
                              0
                              • D David Crow

                                lctrncs wrote:

                                ...this is where I have instantiated m_wndComboBox...

                                m_wndComboBox should be a member variable, not local to some function.


                                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                "Judge not by the eye but by the heart." - Native American Proverb

                                L Offline
                                L Offline
                                lctrncs
                                wrote on last edited by
                                #31

                                As I said, I have never tried to instantiate a class instance so that I can use the dot operator. I tried to instantiate it in a number of locations (mainframe.cpp main.c etc.) without success. So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest m_combo.InsertStinrg(0,"") ? Why should the dot operator work when a pointer does not?

                                "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                D 1 Reply Last reply
                                0
                                • L lctrncs

                                  As I said, I have never tried to instantiate a class instance so that I can use the dot operator. I tried to instantiate it in a number of locations (mainframe.cpp main.c etc.) without success. So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest m_combo.InsertStinrg(0,"") ? Why should the dot operator work when a pointer does not?

                                  "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #32

                                  lctrncs wrote:

                                  So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest

                                  It should belong to the class that owns it (hence the m_ prefix). In my example, m_combo and m_list are both members of CMyDialog.

                                  lctrncs wrote:

                                  Why should the dot operator work when a pointer does not?

                                  Pointer variables use ->, while non-pointer variables use a dot. In reality,

                                  pointer->member

                                  is equivalent to:

                                  (*pointer).member

                                  See here for more on the member-selection operator.


                                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                  "Judge not by the eye but by the heart." - Native American Proverb

                                  L 1 Reply Last reply
                                  0
                                  • D David Crow

                                    lctrncs wrote:

                                    So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest

                                    It should belong to the class that owns it (hence the m_ prefix). In my example, m_combo and m_list are both members of CMyDialog.

                                    lctrncs wrote:

                                    Why should the dot operator work when a pointer does not?

                                    Pointer variables use ->, while non-pointer variables use a dot. In reality,

                                    pointer->member

                                    is equivalent to:

                                    (*pointer).member

                                    See here for more on the member-selection operator.


                                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                    "Judge not by the eye but by the heart." - Native American Proverb

                                    L Offline
                                    L Offline
                                    lctrncs
                                    wrote on last edited by
                                    #33

                                    So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?

                                    "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                    D 1 Reply Last reply
                                    0
                                    • L lctrncs

                                      So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?

                                      "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #34

                                      lctrncs wrote:

                                      So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?

                                      No. Use ClassWizard (Ctrl+W) to associate a member variable with a control.


                                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                      "Judge not by the eye but by the heart." - Native American Proverb

                                      1 Reply Last reply
                                      0
                                      • D David Crow

                                        Ok, what I have here may help, or it may not since it is not entirely like what you have. I have a CRecordset-derived class that reads from the Employees table of the Northwind database. I have a dialog with a combobox (having the CBS_DROPDOWNLIST style) and listbox. Selecting an item from the combobox will add it to the listbox. The selection in the combobox is then cleared.

                                        BOOL CMyDlg::OnInitDialog()
                                        {
                                        CDialog::OnInitDialog();

                                        CDatabase db;
                                        CSet rs(&db);
                                        
                                        rs.Open();
                                        while (! rs.IsEOF())
                                        {
                                            m\_combo.AddString(rs.m\_LastName);
                                            rs.MoveNext();
                                        }
                                        
                                        rs.Close();
                                        
                                        m\_combo.InsertString(0, "");
                                         
                                        return TRUE;  // return TRUE  unless you set the focus to a control
                                        

                                        }

                                        void CMyDlg::OnSelchangeCombo1()
                                        {
                                        int nIndex = m_combo.GetCurSel();
                                        CString strItem;
                                        m_combo.GetLBText(nIndex, strItem);
                                        m_list.AddString(strItem);

                                        m\_combo.SetCurSel(0);
                                        

                                        }

                                        Is this close?


                                        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                        "Judge not by the eye but by the heart." - Native American Proverb

                                        L Offline
                                        L Offline
                                        lctrncs
                                        wrote on last edited by
                                        #35

                                        Well I got things running like you show here - the Class Wizard info was key - but it still does not clear the edit box in either dropdown or drop list mode - any other suggestions?

                                        "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                        D 1 Reply Last reply
                                        0
                                        • L lctrncs

                                          Well I got things running like you show here - the Class Wizard info was key - but it still does not clear the edit box in either dropdown or drop list mode - any other suggestions?

                                          "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #36

                                          If you can narrow this project down to just the relevant lines, you can e-mail it to me and I'll take a look.


                                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                          "Judge not by the eye but by the heart." - Native American Proverb

                                          L 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