Combo Boxes - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Combo Boxes

Description:

Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach ... List property is used to show current list item selected ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 11
Provided by: alkaha
Category:
Tags: boxes | combo

less

Transcript and Presenter's Notes

Title: Combo Boxes


1
Combo Boxes List Boxes
  • List Box
  • User selects from predefined set of textual
    choices
  • Index number of the users selection is stored in
    ListIndex property
  • There is no Text property!
  • List property is used to show current list item
    selected
  • ListCount property is equal to the number of
    items in the list box
  • Combo Box
  • User selects from predefined set of textual
    choices or enters own textual response
  • Selected response is assigned to Text property
  • Style property determines whether list will also
    have textbox or not as well as whether list will
    drop down or not

Each item in list has an index value, starting at
0 for the first item
2
Filling a list
  • Design time
  • List property
  • 1) Type entry
  • 2) Press Ctrl-Enter
  • 3) Type next entry
  • 4) Repeat 2 3 above until last entry has been
    added
  • 5) Press ENTER or click anywhere else to complete
    the operation
  • In code
  • AddItem method
  • Call lstEx.AddItem(Apple)
  • Call lstEx.AddItem(Banana)
  • Call lstEx.AddItem(Carrot)
  • Call lstEx.AddItem(Donut)
  • Call cboEx.AddItem(Ape)
  • Call cboEx.AddItem(Bear)
  • Call cboEx.AddItem(Cat)

3
Removing individual list items
  • Design time
  • List property
  • 1) Highlight only the individual item to be
    deleted
  • 2) Press DELETE
  • 3) Press ENTER or click anywhere else to complete
    the operation
  • In code
  • RemoveItem method
  • Call lstEx.RemoveItem(0)
  • will remove first item from list
  • Call cboEx.RemoveItem(3)
  • will remove fourth item from list
  • Index values of list items is updated

4
Clearing a list
  • Design time
  • List property
  • 1) Highlight entire selection
  • 2) Press DELETE key to erase all items in list
  • In code
  • Clear method
  • Assume lstEx has four items (Apple, Banana,
    Carrot, and Donut), and cboEx has three items
    (Ape, Bear, Cat)
  • Call lstEx.Clear
  • Call cboEx.Clear
  • will erase all contents of the list box lstEx
    and the combo box cboEx

5
Selecting/deselecting from lists
  • ListIndex property identifies which list item is
    selected (highlighted)
  • Controlling list selection at design time or in
    code
  • Select first list item by assigning 0 to
    ListIndex
  • Select another list item by assigning the
    corresponding position number to ListIndex
  • Deselect all items by assigning -1 to ListIndex

6
Sorting lists
  • Sorted property
  • Boolean value that represents whether list items
    are displayed in sorted order or not
  • What is we wanted to preserve the original order?
  • ItemData property can be used to hold the
    original order of the list
  • lstName.ItemData(IndexLocation) Value

7
List Example
  • Private Sub cmdAdd_Click()
  • Call lstEx.AddItem(txtEx.Text vbTab _
  • Format(lstEx.ListCount, "00"))
  • lstEx.ItemData(lstEx.NewIndex)
    lstEx.ListCount - 1
  • Call lstEx2.AddItem(txtEx.Text vbTab _
  • Format(lstEx2.ListCount, "00"))
  • lstEx2.ItemData(lstEx2.NewIndex)
    lstEx2.ListCount - 1
  • txtEx.SelStart 0
  • txtEx.SelLength Len(txtEx.Text)
  • End Sub
  • Private Sub cmdOriginal_Click()
  • lstEx.Visible False
  • lstEx2.Visible True
  • lstEx3.Visible False
  • End Sub
  • Private Sub cmdSort_Click()
  • lstEx.Visible True
  • lstEx2.Visible False
  • lstEx3.Visible False

8
List Example
  • Private Sub cmdItemData_Click()
  • Dim ListLoc As Integer
  • Call lstEx3.Clear
  • For ListLoc 0 To lstEx2.ListCount - 1 Step
    1
  • Call lstEx3.AddItem(lstEx2.List(lstEx2.Ite
    mData(ListLoc)))
  • Next ListLoc
  • lstEx.Visible False
  • lstEx2.Visible False
  • lstEx3.Visible True
  • End Sub

9
Counting items in list
  • Sometimes the number of list items is not
    determined at design time, but the program needs
    to know the total number of items in a list.
  • ListCount property stores the current number of
    items in a list
  • ListCount is always equal to 1 plus the highest
    ListIndex
  • TotalItems lstEx.ListCount

10
For-Next Loops for Lists
Dim LCount As Integer For LCount 0 To
(lstEx.ListCount-1) Step 1 Printer.Print
lstEx.List(LCount) Next LCount steps to process
after loop ends
What changes are needed to print the list items
in reverse order? What processing is needed to
find the total of list items? The minimum? The
maximum?
Write a Comment
User Comments (0)
About PowerShow.com