These controls are used to display a list of values in which the user can choose one or more values. The list box remains fixed and deployed while the combo box appears as a text box with a triangle on the right that allows you to display all the values in the list. One of the easiest ways to create a control like this is using the Control Wizard. Usage is very simple, you only need to activate the wizard before creating the control on the form or report by clicking on its icon in the Toolbox. Once activated, the wizard, when trying to create a list box control or combo box will launch an automatic generator control, following a few simple steps, complete control properties to display the data you want.
ListBox Control
ListBox Control (List) allows the user to select from a list of data (One or several at once). In Visual Basic 6, it was common as well as adding a string to the ListBox also like to add or link a numeric value with the string in the VB version of the method we used to associate ItemData this numerical value, so that each string contained in the ListBox could have an associated numerical value. But. NET ListBox control ItemData not have a method (or a property indicating NewIndex the last index which was added to the ListBox), not only strings are added, as the Items collection that can take are elements of type Object, So we can add any type of data in that collection, not just strings, as in the VB6 ListBox.
In VB6, the elements were of type String, no problems with what was shown in control, because what was shown was precisely the content of the chains that had been added, but because the type of data is added to the Items collection of a ListBox. NET is of type Object. NET Framework does is show how to return the ToString method of each object, we add a string, it displays the contents of the string, add numeric values, shows the contents of those numbers.
Sample Code :
- Class LBItem
- As String Public Content
- Public Value As Integer
- End Class
- Public Sub New (c As String, v As Integer)
- Content = c
- Value = v
- End Sub
The entries in a ListBox can be sorted easily by setting the Sorted property to the development time is set to True.
ComboControl
This control is widely used in programs allows us through a drop-down list to select items, as it is also possible to introduce the same. Another type of views are as follows ComboBox control, you change from the control's Style property.
- Single Column DropDown : The single DropDown column is an kind of the default style and displays the list when you click the arrow.
- Multiple Column DropDown : There is another type where you get multiple columns in the singel box which displayed the list and has a button to display the items.
- Search DropDown: The third type is is like the DropDown, but with the difference that you can enter text, you can only select items.his control is very similar to the List control in regard to the properties and methods for managing data, to add items using the AddItem method.
Code for adding 50 item in Next Loop
Code:
Dim element As Integer
For Item = 0 To 50
'Add the value of the variable element to Combo
Combo1.AddItem i
Next
Like the ListBox control to delete the contents using the Clear method
'Delete all the contents
Combo1.Clear
Like the List control to ascertain the value of a particular item using the List property specifying the item number, ListCount (for the number of elements), ListIndex (know the selected item) RemoveItem Method (Eliminates specified item) etc.
DataField and DataSource Property are two properties present in the ListBox and ComboBox control, as well as several other Visual Basic controls such as Label, TextBox, etc ..., enables setting bind the controls to a database. The first one DataField returns or sets a value that binds a control with a field of current record. And the second one DataSource, sets a value that specifies the data control through which the current control is linked to a database
Bookmarks