Now List Box is another input item but here you can only make a selection from a pre-defined list. to use it just drag a list item from the standard tool box . its default name is List1.
to generate its list we have different methods i.e static list, dynamic list
static list: it is a predifined list of items that is feeded in the list property of the list box at design time.
Dynamic List: In this case the list is generated at runtime either from Database or from somewhere else. this is the best option for generating list.
simple example of list box is that we often select font size from List Box or font style etc.
suppose i have a listbox named List1 and i want to add some items to it at runtime through code then follow the steps below
List1.AddItem("First Value")
List1.AddItem("Second Value")
.
.
.
similarly if i have values in a table in database and want to show them all in a List box then
suppose i have rs as Recordset (we will cover it in full details later on) and the field name in the table is ValuesforList then
'-------------------------------------------
List1.Clear
rs.MoveFirst
Do while rs.EOF=False
List1.AddItem(rs!ValuesforList)
rs.MoveNext
Loop
'-------------------------------------------
This code will first clear previous values from List1 and then navigate through all the records of the recordset and will add the field's ValuesforList values to the List1.
when we use listbox in our project then it will become more clear. for any questions do contact us.
what are other uses of list box??
ReplyDeletecan you give some more examples that how can we utilize list box control?