list box in widget swap drop down lists in gpe naming convention list boxeslst (el es tee – not 1...
TRANSCRIPT
![Page 1: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/1.jpg)
![Page 2: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/2.jpg)
List Box in Widget Swap
![Page 3: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/3.jpg)
Drop Down Lists in GPE
![Page 4: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/4.jpg)
Naming Convention
List boxes lst (El Es Tee – not 1 s t)Drop Down Lists cbo (for combo box – old
name) Or ddl (whichever you use be
consistent)
All examples we shall relate to list boxes however the code also applies to drop down lists
![Page 5: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/5.jpg)
Things we want to do with List Boxes Add an item to the list
Set the entry so it makes sense to the user Set the entry so it makes sense to the system
Remove an item from the list Read the value of the item selected by the
user, i.e. find out what they clicked on Clear the list box Validate a list to make sure that an item has
been selected
![Page 6: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/6.jpg)
The Items CollectionHere we can see three items listed in this
list’s “items collection”
![Page 7: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/7.jpg)
Grouping data in ListsIn computer programming there are various
types of List structures that allow us to store more than one value in a singular structure.
Imagine a list of Strings or Integers or even Objects. (e.g. Employees)
Each item in a list has an Index. This is a numeric integer value that specifies the item’s position within the list. Indexing always starts at zero and ends at the list’s size – 1. In a list of 5 items, the last item will have an index of 4 and the first item an index of 0.
![Page 8: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/8.jpg)
ListBox - collection of ListItemsA ListBox will contain 0, 1 or more ListItem
objects.
The data within a ListBox web control is stored within a List collection that is referred to by Items. (e.g. lstToDo.Items)
Each ListItem has a Text and Value property. The Text is what you see on the screen and the Value is the SystemID.
![Page 9: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/9.jpg)
Accessing a ListBox itemTo access an individual Item within the ListBox
you will use the notation:- lstToDo.Items.Item(i) where i represents the index of the item you wish to access.
For example (set and get Text and Value properties):-lstToDo.Items.Item(0).Text = “Blue Widget”lstToDo.Items.Item(0).Value = “bluewidget.jpg”
Widget = lstToDo.Items.Item(2).TextWidgetImage = lstToDo.Items.Item(2).Value
![Page 10: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/10.jpg)
Identifying What the User SelectstxtSelectedItem.Text =
lstToDo.SelectedValue
Returns the value…
“Ring John”
![Page 11: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/11.jpg)
ListBox PropertieslstNames.SelectedItem.Text This allows us to obtain the text of
the item in the list that has been selected by the user.
lstNames.SelectedValue Contains the system ID of the selected item in the list. (If you do not set this yourself it will be the same as SelectedItem.Text)
lstNames.SelectedIndex This tells us the number of the selected item in the list. (If this is -1 it means that no selection has been made.) Each item in a list box has an index. The first item has an index of zero, the second one and so on.
![Page 12: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/12.jpg)
ListItemCollection PropertieslstNames.Items.Count The items have a count
property that tells us how many items are in the list.
lstNames.Items.Item(2).Text
lstNames.Items.Item(4).Value
Allows us to get or set the Text or system ID Value of an item in the list.
• Note - Items refers to the List collection contained within the List Box
- Item(i) refers to the list item at index i, where i is an integer within the range of the list (0 . . n-1) where n represents the number of items in the list.
![Page 13: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/13.jpg)
ListItemCollection MethodslstNames.Items.Add(MyName)This method allows us to add an item to a list box.
lstNames.Items.RemoveAt(3)Allows us to remove an item from a list box.
lstNames.Items.Clear()Clears the items collection of all entries.
![Page 14: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/14.jpg)
Adding Items to a List BoxIn the following example we will type two values.
Breakfast this is the value that will appear to the user
a this is the identifier for this entry
![Page 15: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/15.jpg)
Once the Item is Added…
![Page 16: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/16.jpg)
Add Some More Items… Lunch b Supper c
![Page 17: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/17.jpg)
Adding Items
![Page 18: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/18.jpg)
Setting the Item’s Value Two things to consider…
The text (that the user sees) The value (that the system uses)
If we have a list with three items it has the following properties...
Index
Items.Count = 3 Breakfast 0
Lunch 1
Supper 2
![Page 19: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/19.jpg)
Consider the Following Code…
![Page 20: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/20.jpg)
Identifying what the User SelectsThe SelectedValue property contains the
identifier of the item (the value) that the user has selected
If we do not explicitly set the value of an item ourselves, the SelectedValue contains the text of the entry in the list
![Page 21: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/21.jpg)
Deleting Items on the List
![Page 22: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/22.jpg)
Ensuring that a User has Selected an Item
![Page 23: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/23.jpg)
Clearing the List BoxShould you wish to clear the entire contents
of the list box, you would use the Clear method
For example, the following code would clear a list box called lstListExample
lstListExample.Items.Clear
![Page 24: List Box in Widget Swap Drop Down Lists in GPE Naming Convention List boxeslst (El Es Tee – not 1 s t) Drop Down Listscbo (for combo box – old name)](https://reader035.vdocuments.net/reader035/viewer/2022062511/5518d09b550346881f8b5d06/html5/thumbnails/24.jpg)
Questions1. Write a section of code that adds the days of
the week to the list box lstDays. (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
2. Write a line of code that removes “Wed”
from the list box. 3. Write a section of code that validates if an
item has been selected in the list box lstRoomForBooking