Welcome to Dream.In.Code
Become a VB Expert!

Join 137,233 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,781 people online right now. Registration is fast and FREE... Join Now!




combo box problem

 
Reply to this topicStart new topic

combo box problem, addind combo box items from code

bluesun011
12 Mar, 2007 - 04:36 PM
Post #1

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 1


My Contributions
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


User is offlineProfile CardPM
+Quote Post

Jayman
RE: Combo Box Problem
12 Mar, 2007 - 05:12 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You can add items using the Items.Add method. The following will add: First and Second to the combox.
CODE

Me.ComboBox1.Items.Add("First")
Me.ComboBox1.Items.Add("Second")

User is online!Profile CardPM
+Quote Post

Episonage
RE: Combo Box Problem
13 Mar, 2007 - 02:57 AM
Post #3

New D.I.C Head
Group Icon

Joined: 10 Feb, 2007
Posts: 22


Dream Kudos: 25
My Contributions
QUOTE(bluesun011 @ 12 Mar, 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


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
CODE

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.
CODE

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.
CODE

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...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:41PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month