Download presentation
Presentation is loading. Please wait.
1
VB Default Controls List Box, Combo Box
2
Default Controls
3
List Box ListBox control can used the to present a list of choices.
The key parts of the list box are the following: Item list: This is the list of items from which the users can select. These items are added to the list in the design environment or by the program as it is running. Selected item: This item is chosen by the users. Scrollbar: This part indicates that more items are available on the list than will fit in the box.
4
Adding Items to List Box at design-time
List box items can be added at design time by using the “List” property of the control. After you add an item to the list, press Ctrl+Enter to move to the next line of the list.
5
Adding Items to List Box at Programmatically
Using addItem method: Example: Private Sub Form_Load() Dim i As Integer For i = 1 To 100 List1.AddItem “This is item “ & i Next i End Sub
6
Other List Box Methods & properties
To clear all the items in a list box, use the Clear method: List1.Clear To refer to a list item use the list() array: List1.list(0) First Item List1.list(1) Second item ListCount represents the number of items in a list box. For i = 0 To List1.ListCount - 1 Print List1.List(i) Next i
7
Other List Box Methods & properties
ListIndex property represents the selected item. Listindex is –1 if no item is selected. Msgbox List1.List(List1.ListIndex) Text property contains the selected item text, If no list box item has yet been clicked, the Text property contains an empty string (“”). MsgBox List1.Text To remove items from the list box, use the RemoveItem method: List1.RemoveItem List1.ListIndex
8
List Box Items Position
To add an item in a specific position (index): lstAvailable.AddItem “Apples”, 2 To sort list box item, set the Sorted property to True. (designtime only)
9
Appearance of a List Box
Style property: Standard Checkbox Columns property: 0 for single columns 1,2,3,… for the number of columns appearing at one time
10
Working with Multiple Selections
MultiSelect property allows the user to select more than one item: 0 : None only one selection at a time 1 : Simple users can click an item with the mouse to select it or click a selected item to deselect it 2 : Extended users can select a range of items by clicking the first item in the range and then, while holding down the Shift key, clicking the last item in the range; all items in between the first and last item are selected. To add or delete a single item to or from this selection, users hold down the Ctrl key while clicking the item.
11
Working with Multiple Selections
ListIndex property works only for a single selection You have to examine each item in the list to determine whether it is selected. Whether an item is selected is indicated by the list box’s Selected property. True (item selected) False (Item not selected) Example: For I = 0 to List1.ListCount - 1 If List1.Selected(I) Then Print List1.List(I) Next I
12
Keeping Other Data in the List
ItemData property of a list box is an array of long integers, one for each item that has been added to the list box. NewIndex property contains the index number of the most recently added item in the list. lstCCode.AddItem “Egypt” lstCCode.ItemData(lstCCode.NewIndex) = 20 lstCCode.AddItem “Saudi Arabia” lstCCode.ItemData(lstCCode.NewIndex) = 966 Retreving the Data of an Item: Msgbox lstCCode.ItemData(lstCCode.ListIndex)
13
The Combo Box Enables you to present lists to the users
can be used in three different forms: The drop-down combo box: Presents the users with a text box combined with a dropdown list. The users can either select an item from the list portion or type an item in the text box portion. The simple combo box: Displays a text box and a list that doesn’t drop down. the users can either select an item from the list portion or type an item in the text box portion. The drop-down list: Displays a drop-down list box from which the users can make a choice. The users cannot enter items that are not in the list.
14
The drop-down combo box
15
The simple combo box
16
The drop-down list
17
Combo Box features Use the AddItem, RemoveItem, and Clear methods to modify the contents of the list. Sorted or an unsorted list. Support the ItemData array and NewIndex property. No multiple choices Combo boxes Allows the users to enter choices that are not on the list. Drop-down list is useful for presenting several choices in a small amount of space.
18
Creating a Combo Box Draw a combo box on your form
Select its style from the property window Add items to the List property at design or run time
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.