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. Combo Box, SetCurSel ( 0 )

Combo Box, SetCurSel ( 0 )

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasehelp
7 Posts 4 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.
  • K Offline
    K Offline
    kevincwong
    wrote on last edited by
    #1

    Hi, I created a dialog with a combo box. I entered a few items ("A;B;C;D") to the combox box's property->data field. I know I need to call SetCurSel ( ) function to sets the combo box's current selection by a data index. Otherwise, the combo box appers empty until I drop the list down. I also read something about fixing the problem in OnInitDialog ( ). But I could not find out how they come together. I think my question is where is "OnInitDialog". Should I derive a new class from that combo box? If that is the case, how my dialog display the same combo box again? Any suggestions would be appreciated? Thanks, Kevin

    G M 2 Replies Last reply
    0
    • K kevincwong

      Hi, I created a dialog with a combo box. I entered a few items ("A;B;C;D") to the combox box's property->data field. I know I need to call SetCurSel ( ) function to sets the combo box's current selection by a data index. Otherwise, the combo box appers empty until I drop the list down. I also read something about fixing the problem in OnInitDialog ( ). But I could not find out how they come together. I think my question is where is "OnInitDialog". Should I derive a new class from that combo box? If that is the case, how my dialog display the same combo box again? Any suggestions would be appreciated? Thanks, Kevin

      G Offline
      G Offline
      Graham Bradshaw
      wrote on last edited by
      #2

      OnInitDialog is called by the framework before the dialog is displayed. It's an ideal place to do the sort of thing you want to do (fill combo boxes, set text in text boxes etc). It's a member function of CDialog, so (assuming you're using MFC), you'll need to override this function and put your code in there. Note that although you are ultimately handling a WM_INITDIALOG message, in this case you don't need an entry in the message map, just an override of the base class function.

      1 Reply Last reply
      0
      • K kevincwong

        Hi, I created a dialog with a combo box. I entered a few items ("A;B;C;D") to the combox box's property->data field. I know I need to call SetCurSel ( ) function to sets the combo box's current selection by a data index. Otherwise, the combo box appers empty until I drop the list down. I also read something about fixing the problem in OnInitDialog ( ). But I could not find out how they come together. I think my question is where is "OnInitDialog". Should I derive a new class from that combo box? If that is the case, how my dialog display the same combo box again? Any suggestions would be appreciated? Thanks, Kevin

        M Offline
        M Offline
        Mohammad A Gdeisat
        wrote on last edited by
        #3

        Hi- go to class wizard and select the dialog box class on which your combo box is in, then from create an event handler(also from class wizard) for the WM_INITDIALOG message or the OnInitDialog() function, place your code to initialize (select the item you want in a combo box), the code in this function will be executed when your dialog box is initialized, and before it is visible on the screen. Regrds, Mohammad Gdeisat And ever has it been that love knows not its own depth until the hour of separation

        K 1 Reply Last reply
        0
        • M Mohammad A Gdeisat

          Hi- go to class wizard and select the dialog box class on which your combo box is in, then from create an event handler(also from class wizard) for the WM_INITDIALOG message or the OnInitDialog() function, place your code to initialize (select the item you want in a combo box), the code in this function will be executed when your dialog box is initialized, and before it is visible on the screen. Regrds, Mohammad Gdeisat And ever has it been that love knows not its own depth until the hour of separation

          K Offline
          K Offline
          kevincwong
          wrote on last edited by
          #4

          Great, it works. One more question. I have about 15 data (a;b;c;d;e;...) with my combo box. When I clicked the combo box, it only showed one entry at a time when I hit the up or down arrow. How can I show multiple rows to be selected? Thanks, Kevin

          S 1 Reply Last reply
          0
          • K kevincwong

            Great, it works. One more question. I have about 15 data (a;b;c;d;e;...) with my combo box. When I clicked the combo box, it only showed one entry at a time when I hit the up or down arrow. How can I show multiple rows to be selected? Thanks, Kevin

            S Offline
            S Offline
            S Douglas
            wrote on last edited by
            #5

            kevincwong wrote:

            How can I show multiple rows

            If you want the combo box to display more than on item when clicked, try this In design mode, Right click on the drop down box, Use the selection box to resize the height.


            DEBUGGING : Removing the needles from the haystack.

            K 1 Reply Last reply
            0
            • S S Douglas

              kevincwong wrote:

              How can I show multiple rows

              If you want the combo box to display more than on item when clicked, try this In design mode, Right click on the drop down box, Use the selection box to resize the height.


              DEBUGGING : Removing the needles from the haystack.

              K Offline
              K Offline
              kevincwong
              wrote on last edited by
              #6

              I got it. It works. Thank you so much! Kevin

              S 1 Reply Last reply
              0
              • K kevincwong

                I got it. It works. Thank you so much! Kevin

                S Offline
                S Offline
                S Douglas
                wrote on last edited by
                #7

                kevincwong wrote:

                Thank you so much!

                No problem...


                DEBUGGING : Removing the needles from the haystack.

                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