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. MFC Combobox help please...

MFC Combobox help please...

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
7 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.

    A N S 3 Replies Last reply
    0
    • L Lost User

      How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.

      A Offline
      A Offline
      aldeba
      wrote on last edited by
      #2

      Let's say the button is called IDC_BUTTON1 So i guess by now u should know how to do a event for IDC_BUTTON1? Hook on the msg BN_CLICKED. So let's say you have assigned the combobox to a variable called m_comboBox. This can be done thru class wizard. You would get void ClassName::OnButton1 { m_comboBox.AddString("....");// Your random data } Hope this helps.

      L 1 Reply Last reply
      0
      • A aldeba

        Let's say the button is called IDC_BUTTON1 So i guess by now u should know how to do a event for IDC_BUTTON1? Hook on the msg BN_CLICKED. So let's say you have assigned the combobox to a variable called m_comboBox. This can be done thru class wizard. You would get void ClassName::OnButton1 { m_comboBox.AddString("....");// Your random data } Hope this helps.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I'm sorry, perhaps I didn't explained in detail what I want to achieved. Say my combobox have 5 data entries (properties -> data) data1 data2 data3 data4 data5 When you press the button, it pick one of those entries and make it the display entry.

        1 Reply Last reply
        0
        • L Lost User

          How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Generate a random number between 0 and CComboBox::GetCount() - 1 Now use CComboBox::GetLBText() on this random number. Is that what you wanted? Now each time you get a random entry from the combo box Nish


          Author of the romantic comedy Summer Love and Some more Cricket [New Win]

          1 Reply Last reply
          0
          • L Lost User

            How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.

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

            To generate random numbers, use the srand(time(NULL)) to seed the generator. Then use rand() to get a random number between 0 and MAX_INT (4 billion or so). To scale this massive range down to that of your listbox, use this formula: rand() % listbox.ItemCount (or whatever the property is) That will generate a number between zero and listbox.ItemCount - 1. You +/- and constant value if you need to shift the lower limit or use rand() % (listbox.ItemCount + x) to shift the upper limit.

            L 1 Reply Last reply
            0
            • S sultan_of_6string

              To generate random numbers, use the srand(time(NULL)) to seed the generator. Then use rand() to get a random number between 0 and MAX_INT (4 billion or so). To scale this massive range down to that of your listbox, use this formula: rand() % listbox.ItemCount (or whatever the property is) That will generate a number between zero and listbox.ItemCount - 1. You +/- and constant value if you need to shift the lower limit or use rand() % (listbox.ItemCount + x) to shift the upper limit.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This will be my last time asking, please try to help me this last time. rand() % listbox.ItemCount I understand that, but say I have a combobox name IDC_COMBO1, how do I tell its name to use inside my codes?

              D 1 Reply Last reply
              0
              • L Lost User

                This will be my last time asking, please try to help me this last time. rand() % listbox.ItemCount I understand that, but say I have a combobox name IDC_COMBO1, how do I tell its name to use inside my codes?

                D Offline
                D Offline
                Duane
                wrote on last edited by
                #7

                To assign a value to the Combobox use the Class Wizard. The steps to do this are: 1. bring up the class wizard (menu VIEW--> ClassWizard). 2. Go to the Member Variables tab. 3. Select the IDC_COMBO1 control ID and them press the ADD VARIABLE button. 4. Give the variable a name, set category to VALUE and press OK.

                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