combo box problem

addind combo box items from code

Page 1 of 1

2 Replies - 5061 Views - Last Post: 13 March 2007 - 03:57 AM Rate Topic: -----

#1 bluesun011  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-March 07

combo box problem

Posted 12 March 2007 - 05:36 PM

Im trying to add the numeric 1-14 to a drop down combo box. Even though it would probly be more efficent to do it throough the properities window. I want to be able to code it so that the numbers will be added through the code during the runtime of the program,

Thanks for any help
Is This A Good Question/Topic? 0
  • +

Replies To: combo box problem

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: combo box problem

Posted 12 March 2007 - 06:12 PM

You can add items using the Items.Add method. The following will add: First and Second to the combox.
Me.ComboBox1.Items.Add("First")
Me.ComboBox1.Items.Add("Second")


Was This Post Helpful? 0
  • +
  • -

#3 Episonage  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 10-February 07

Re: combo box problem

Post icon  Posted 13 March 2007 - 03:57 AM

View Postbluesun011, on 12 Mar, 2007 - 05:36 PM, said:

Im trying to add the numeric 1-14 to a drop down combo box. Even though it would probly be more efficent to do it throough the properities window. I want to be able to code it so that the numbers will be added through the code during the runtime of the program,

Thanks for any help


Okay, the cheapest (and the fastest) way would be to put Combobox1.AddItem "1" in form_load, but what if you need to change list, and refresh it during run-time?
Then the best thing to use would be the For-to loop...
In case you don't know how, I'll explain
Dim i as Integer 'The number that will change, with the loop
Dim Beginning as Integer 'The minimum number
Dim Ending as Integer 'The maximum number
For i = Beginning To Ending '(You can also add steps)
	 'statements
	 'statements
	 'statements
Next Beginning


Okay, so the easyest way to refresh (and fill) the list would be to use this loop, in a private sub. Private subs happen only if you call them, so this makes it perfect.
Dim i as Integer 'The same "i" as above
Private Sub RefreshCombo(Min as Integer, Max as Integer) 'We will use Min and Max when we call the sub, to assign the 'range of numbers the loop should put in list.
For i = Min to Max 'We now use the data we've given when calling the sub.
	ComboBox1.AddItem i 'This will add the number to the combo box.
Next i 'End the statement, which continues the loop from the top, unless i = Max

End Sub


Now that we have our decleration, we might want to call it.
Private Sub Command1_Click(Button as integer, blah balh)
Call RefreshCombo (5,200) 'This calls our sub, givin it the attributes of 5 and 200
'In the loop we use those numbers as Min and Max, meaning that our loop will put all
' the numbers from 5 to 200 into the combo box
End sub


Well that's about it... I hope it helpes...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1