MFC Combobox help please...
-
How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.
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.
-
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.
-
How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.
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]
-
How do I code it so that when a button is press the data on the ComboBox randomize? Please help this newbie programmer.
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.
-
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.
-
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?
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.