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 - set to display the nth string

Combo box - set to display the nth string

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
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.
  • J Offline
    J Offline
    jimNLX
    wrote on last edited by
    #1

    I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help

    R I 2 Replies Last reply
    0
    • J jimNLX

      I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      From MSDN : CComboBox::SetCurSel int SetCurSel( int nSelect ); Remarks Selects a string in the list box of a combo box. If necessary, the list box scrolls the string into view (if the list box is visible). The text in the edit control of the combo box is changed to reflect the new selection. Any previous selection in the list box is removed. ~RaGE();

      1 Reply Last reply
      0
      • J jimNLX

        I have a combo box that I create on a dialog window by adding strings to it from a file. Once a selection is made the box shows that selection as long as I keep the window open. But after I close it and return the box is blank until it is selected again. Is there anyway to init this to display a certain item? I have the index that I wand to set it too.. Thanks for any help

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        Check out CComboBox::SetCurSel / CB_SETCURSEL. You have to be careful if the combobox is sorted, but CB_ADDSTRING gives you the "post sorting" number. Iain.

        K 1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          Check out CComboBox::SetCurSel / CB_SETCURSEL. You have to be careful if the combobox is sorted, but CB_ADDSTRING gives you the "post sorting" number. Iain.

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

          when using addstring, is there a way to haVE it not ssort the list? im trying to get the word 'none' to come up as default, but another choice in the listbof is 'channel1' so it comes up default. if it wasnt sorted, it would take the first string i put in and use that one. :(

          I 1 Reply Last reply
          0
          • K keegan

            when using addstring, is there a way to haVE it not ssort the list? im trying to get the word 'none' to come up as default, but another choice in the listbof is 'channel1' so it comes up default. if it wasnt sorted, it would take the first string i put in and use that one. :(

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            Just remove the LBS_SORT style. In the resource editor, select the combo box. Bring up its property box. On the 2nd or third tab there is a check box for "sort". Clear the check. Compile. Enjoy! Iain.

            K 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Just remove the LBS_SORT style. In the resource editor, select the combo box. Bring up its property box. On the 2nd or third tab there is a check box for "sort". Clear the check. Compile. Enjoy! Iain.

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

              ok that works great. now, if anyone sees this, is there a way to get a number returned by SetCurSel()? i need to output which value in my listbox is selected. setcursel(0) forces the first string to be selected. so, if the user changes the selected variable, a number has to be stored somewhere because the program remembers it. so....where is that number at? *.*

              I 1 Reply Last reply
              0
              • K keegan

                ok that works great. now, if anyone sees this, is there a way to get a number returned by SetCurSel()? i need to output which value in my listbox is selected. setcursel(0) forces the first string to be selected. so, if the user changes the selected variable, a number has to be stored somewhere because the program remembers it. so....where is that number at? *.*

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                This is pretty basic stuff... You should find all this information in the MSDN libraries, or any half-decent MFC/Win32 book. Anyway, as I'm in a nice mood... ;) Lookup: CComboBox::GetCurSel (). DDX_CBIndex (...). Just about any example in the Combo Box section here on CodeProject. Iain.

                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