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. CComboBox

CComboBox

Scheduled Pinned Locked Moved C / C++ / MFC
question
13 Posts 5 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.
  • H Offline
    H Offline
    harsha_1234
    wrote on last edited by
    #1

    Hi all, i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box. i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box if i am doing m_wndCombo.SetWindowText("Default"); in InitDialog then it does not show that "Default" string in combo box. how can i get both the feautures? means noneditable and should be able to set the default values at start of dialog!! Is it possible with combo box?? Thanks and regards Harshal

    R N M D 4 Replies Last reply
    0
    • H harsha_1234

      Hi all, i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box. i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box if i am doing m_wndCombo.SetWindowText("Default"); in InitDialog then it does not show that "Default" string in combo box. how can i get both the feautures? means noneditable and should be able to set the default values at start of dialog!! Is it possible with combo box?? Thanks and regards Harshal

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      harsha_1234 wrote:

      m_wndCombo.SetWindowText("Default");

      Drop is not only for the user. Its for you too. If it is drop list, then you could only select what is available. Therefore you need to add a string before you could display it. Try this: m_wndCombo.AddString("Default Value");

      harsha_1234 wrote:

      m_wndCombo.SetWindowText("Default");

      Use the CComboBox::SetCurSel() function to set the selection.

      Nobody can give you wiser advice than yourself. - Cicero

      1 Reply Last reply
      0
      • H harsha_1234

        Hi all, i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box. i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box if i am doing m_wndCombo.SetWindowText("Default"); in InitDialog then it does not show that "Default" string in combo box. how can i get both the feautures? means noneditable and should be able to set the default values at start of dialog!! Is it possible with combo box?? Thanks and regards Harshal

        N Offline
        N Offline
        Nibu babu thomas
        wrote on last edited by
        #3

        harsha_1234 wrote:

        i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box

        Use SetCurSel to set currently selected item. You cannot use SetWindowText for this purpose. You can set the initial index of the combo box in OnInitDialog.


        Nibu thomas A Developer Programming tips[^]  My site[^]

        R 1 Reply Last reply
        0
        • H harsha_1234

          Hi all, i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box. i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box if i am doing m_wndCombo.SetWindowText("Default"); in InitDialog then it does not show that "Default" string in combo box. how can i get both the feautures? means noneditable and should be able to set the default values at start of dialog!! Is it possible with combo box?? Thanks and regards Harshal

          M Offline
          M Offline
          Mila025
          wrote on last edited by
          #4

          Hi, Use int SetCurSel( int nSelect ); or if you already have to selecting by text from list SelectString( int nStartAfter, LPCTSTR lpszString );

          ----------- Mila

          H 1 Reply Last reply
          0
          • N Nibu babu thomas

            harsha_1234 wrote:

            i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box

            Use SetCurSel to set currently selected item. You cannot use SetWindowText for this purpose. You can set the initial index of the combo box in OnInitDialog.


            Nibu thomas A Developer Programming tips[^]  My site[^]

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #5

            Nibu babu thomas wrote:

            Maybe in OnInitDialog.

            Not even there. SetWindowText refers to the window as a whole. I haven't tried this but in my opinion, it will not set the display value of the combobox.

            Nobody can give you wiser advice than yourself. - Cicero

            N 1 Reply Last reply
            0
            • M Mila025

              Hi, Use int SetCurSel( int nSelect ); or if you already have to selecting by text from list SelectString( int nStartAfter, LPCTSTR lpszString );

              ----------- Mila

              H Offline
              H Offline
              harsha_1234
              wrote on last edited by
              #6

              oh thanks but how can i do this way like if i have a dropdown combo and i want to make the edit control non editable is it possible?? actually i have used CComboBox with dropdown property every where and till now i was checking the selected text on OnOk but if now if i want that combo to be dropdown and with non editable edit control !! is it possible?? Thanks and regards Harshal

              R M 2 Replies Last reply
              0
              • R Rajesh R Subramanian

                Nibu babu thomas wrote:

                Maybe in OnInitDialog.

                Not even there. SetWindowText refers to the window as a whole. I haven't tried this but in my opinion, it will not set the display value of the combobox.

                Nobody can give you wiser advice than yourself. - Cicero

                N Offline
                N Offline
                Nibu babu thomas
                wrote on last edited by
                #7

                brahmma wrote:

                Not even there. SetWindowText refers to the window as a whole.

                When did I say that? :| You should read carefully before commenting.


                Nibu thomas A Developer Programming tips[^]  My site[^]

                R 1 Reply Last reply
                0
                • N Nibu babu thomas

                  brahmma wrote:

                  Not even there. SetWindowText refers to the window as a whole.

                  When did I say that? :| You should read carefully before commenting.


                  Nibu thomas A Developer Programming tips[^]  My site[^]

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  I did not tell you said anything. I said, setwindowtext refers to the window as a whole. It is more abstract and won't set the text value of the current selected item. Your opinion was that it may work in initdialog. I said an am saying it won't even work there!

                  Nobody can give you wiser advice than yourself. - Cicero

                  N 1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    I did not tell you said anything. I said, setwindowtext refers to the window as a whole. It is more abstract and won't set the text value of the current selected item. Your opinion was that it may work in initdialog. I said an am saying it won't even work there!

                    Nobody can give you wiser advice than yourself. - Cicero

                    N Offline
                    N Offline
                    Nibu babu thomas
                    wrote on last edited by
                    #9

                    brahmma wrote:

                    Your opinion was that it may work in initdialog.

                    Wrong! What I meant was that he should use SetCurSel in OnInitDialog.


                    Nibu thomas A Developer Programming tips[^]  My site[^]

                    R 1 Reply Last reply
                    0
                    • N Nibu babu thomas

                      brahmma wrote:

                      Your opinion was that it may work in initdialog.

                      Wrong! What I meant was that he should use SetCurSel in OnInitDialog.


                      Nibu thomas A Developer Programming tips[^]  My site[^]

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #10

                      Nibu babu thomas wrote:

                      Wrong! What I meant was that he should use SetCurSel in OnInitDialog.

                      Okay.

                      Nobody can give you wiser advice than yourself. - Cicero

                      1 Reply Last reply
                      0
                      • H harsha_1234

                        oh thanks but how can i do this way like if i have a dropdown combo and i want to make the edit control non editable is it possible?? actually i have used CComboBox with dropdown property every where and till now i was checking the selected text on OnOk but if now if i want that combo to be dropdown and with non editable edit control !! is it possible?? Thanks and regards Harshal

                        R Offline
                        R Offline
                        Rajesh R Subramanian
                        wrote on last edited by
                        #11

                        harsha_1234 wrote:

                        if i have a dropdown combo and i want to make the edit control non editable is it possible??

                        Why on earth would you need it? Use the drop list style straight away. Handle the CBN_SELCHANGE and that will help you realise selection change in the combo box.

                        Nobody can give you wiser advice than yourself. - Cicero

                        1 Reply Last reply
                        0
                        • H harsha_1234

                          oh thanks but how can i do this way like if i have a dropdown combo and i want to make the edit control non editable is it possible?? actually i have used CComboBox with dropdown property every where and till now i was checking the selected text on OnOk but if now if i want that combo to be dropdown and with non editable edit control !! is it possible?? Thanks and regards Harshal

                          M Offline
                          M Offline
                          Mila025
                          wrote on last edited by
                          #12

                          Hi, I don't know why you insist on dropdown style - I think in your case drop list is more proper. You can try to override CBN_EDITUPDATE message: "The CBN_EDITUPDATE notification message is sent when the edit control portion of a combo box is about to display altered text. This notification message is sent after the control has formatted the text, but before it displays the text."

                          ----------- Mila

                          1 Reply Last reply
                          0
                          • H harsha_1234

                            Hi all, i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box. i tried with changing it's type to drop list by that way it becomes only selectable but i can not set the default values in that combo box if i am doing m_wndCombo.SetWindowText("Default"); in InitDialog then it does not show that "Default" string in combo box. how can i get both the feautures? means noneditable and should be able to set the default values at start of dialog!! Is it possible with combo box?? Thanks and regards Harshal

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

                            harsha_1234 wrote:

                            i have a combo box whose type is dropdown and i want that it should be only selectable i mean user should not be able to edit in that combo box.

                            You can't. By using the CBS_DROPDOWN or CBS_SIMPLE style, there will be an edit control as part of the combobox. If you do not want this, you must use the CBS_DROPDOWNLIST style instead.


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