Thursday, May 28, 2009

VB-Day Five (5) Combo Box

Combo Box is another Input Item. Basically Combo box is the combination of Text Box and List Box i.e it gives you the functionality of Typing into it and also can make selection from it. it is more flexiable. the background of Combo box is also the same as of List box and also the method of adding values to it is identical as of List box. the only difference in Combo Box and List Box is that from List Box you are only given the option of Selection and can't type into it but here in Combo Box you have both the options i.e can make the selection as well as can type into it your own at run time.

same procedures can be applied to combo box too as of list box. i.e Static list and Dynamic List

Static List: in this list you just use its list property and add values at design time. one thing more that when you are adding values to list property, pressing just enter will lead you loose your focus from list property so make sure that you press Ctrl+Enter to remain in the List property and to move to next line to enter new value.

Dynamic List: ITs the same as of ListBox, you can generate it through code at runtime either from a database or from other source. the code is also the same for example i have a combo box named Combo1 and want to add some values to it at runtime then

Combo1.AddItem("First Value")
Combo1.AddItem("Second Value")
and so on

also if you want to populate it from a database then
suppose my recordset is rs ( we will cover it with database in detail later). the field name i want to display in combo box is SchoolName then

'-------------------------------------------
rs.MoveFirst
Combo1.Clear

Do While rs.EOF=False

Combo1.AddItem(rs!SchoolName)
rs.MoveNext

Loop
'---------------------------------------------
this is a simple way to show values of a table in combo box
for any queries please feel free to contact us.

2 comments:

  1. I think you are doing a good job but still need to improve the objects and need to add more examples so that a beginner can have more directions to follow.

    ReplyDelete
  2. what are the benifits of combo box over list box?

    ReplyDelete