Presentation is loading. Please wait.

Presentation is loading. Please wait.

List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)

Similar presentations


Presentation on theme: "List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)"— Presentation transcript:

1 List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)

2 2 List box, Combo box ? Pointer Label Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shapes Image Box Object Linking Embedding Picture Box Text Box Command Button Option Button List Box Vertical Scroll Bar Drive List Box File List Box Lines Data Tool The Toolbox List box with scroll bar List box without scroll bar Dropdown Combo box Simple Combo box

3 3 Typical use of List and Combo boxes

4 4 List box control n Displays a list of items from which the user can select one or more. n If the number of items exceeds the number that can be displayed, a scroll bar is automatically added n Common properties: – List Array of items in the list box (Note: index=0 through n) – Sorted True or False (items in alphabetical order) – Multiselect (0, 1 or 2 for No-multiple, Simple-Multiple or Multiple selection) – Text Returns item currently highlighted Examples: lstEmployee.Multiselect = 2 lstEmployee.Sorted = True lstEmployee.List(0) = “John” picOutput.Print lstEmployee.Text

5 5 List box control n Common Methods: – AddItem item Adds the item referred to as item to the list – RemoveItem n Removes the item of index n from the list box – Clear Deletes all items in the list box – ListCount Returns the # of items in the list box – ListIndex Returns the index of the item currently highlighted in the list box. – NewIndex Returns the index of the most recently added item Examples: – lstEmployee.AddItem “John” – lstEmployee.RemoveItem 2 – lstEmployee.Clear – NumberOfEmployees = lstEmployee.ListCount – picOutput.Print lstEmployee.NewIndex

6 6 Private Sub Form_Load() lstEmployee.AddItem "Barbara Lewis" lstEmployee.AddItem "John Whashington" lstEmployee.AddItem "Tom Davis" lstEmployee.AddItem "Nathalie Melrose" End Sub Private Sub cmdAdd_Click() Dim item As String item = InputBox("Employee name be to Add:") lstEmployee.AddItem item End Sub Private Sub lstEmployee_Click() picSelected.Cls picSelected.Print "The selected Employee is" picSelected.Print Chr(34) & lstEmployee.Text & Chr(34) & "." End Sub Private Sub LstEmployee_DblClick() lstEmployee.RemoveItem lstEmployee.ListIndex End Sub List box: Example

7 7 List box: Exercise Suppose that the list box lstEmployee is as shown and determine the effect of the code. (Assume the Sorted property is set to True) n picOutput.Print lstEmployee.Text n Answer: n picOutput.Print lstEmployee.List(2) n Answer: n lstEmployee.AddItem “Dan Kelli” n Answer: n lstEmployee.RemoveItem 0 n Answer:

8 8 List box: Exercise Suppose that the list box lstEmployee is as shown and determine the effect of the code. (Assume the Sorted property is set to True) n lstEmployee.AddItem “Dan Kelli” picOutput.Print lstEmployee.NewIndex n Answer: n For n = 0 To lstEmployee.ListCount – 1 lstEmployee.RemoveItem n Next n n Answer:

9 9 Combo box control n A Combo box control combines the features of a Text box control and a List box control – Users can enter information in the text box portion or select an item from the list box portion of the control. n Combo boxes and List boxes have essentially the same – properties – Events – and methods

10 10 Combo box control n Common properties: – List Array of items in the list box (Note: index=0 through n) – Sorted True or False (displaying items in alphabetical order) – Style 0 (Dropdown Combo). Includes a drop-down list and a text box. 1 (Simple Combo). Includes a text box and a list, which doesn't drop down. – Text Returns item currently highlighted Examples: cboEmployee.List(0) = “John” cboEmployee.Sorted = True cboEmployee.Style = 1 picOutput.Print cboEmployee.Text

11 11 Combo box control n Common Methods: – AddItem item Adds the item referred to as item to the list – RemoveItem n Removes the item of index n from the combo box – Clear Deletes all items in the combo box – ListCount Returns the # of items in the combo box – ListIndex Returns the index of the item currently highlighted in the combo box. – NewIndex Returns the index of the most recently added item Examples: – cboEmployee.AddItem “John” – cboEmployee.RemoveItem 2 – cboEmployee.Clear – NumberOfEmployees = cboEmployee.ListCount – picSelected.Print cboEmployee.NewIndex

12 12 Combo box: Exercise Suppose that the combo box cboEmployee appears as shown and that the Sorted property is set to True. Give a statement or statements that carry out the stated task. n Display the item “Barbara Lewis” in picOutput n Answer: n Display the item “John Whashington” in a picOutput n Answer: n Delete the item “Nathalie Melrose” n Answer:

13 13 Combo box: Exercise Suppose that the combo box cboEmployee appears as shown and that the Sorted property is set to True. Give a statement or statements that carry out the stated task. n Add the item “Liza Frulla”. Where will it be inserted? n Answer: n Delete every item beginning with the letter “M”. Use a Do While loop and an If test. n Answer: n Suppose that you should use For..Next instead of Do While, give the correct statements. n Answer

14 14 DriveList box control n A DriveListBox control: – Displays a list of all the valid drives on the computer – Enables a user to select a valid disk drive at run time. n No code is needed to load a DriveList box n Most used property: – DriveContains the name of the currently selected drive Example: Drive = drvExample.Drive n Most used Event – ChangeHappens when the user or program changes the drive selection Example: Private Sub drvExample_Change() picOutput.Print “The New drive is ”; drvExample.Drive End Sub

15 15 DirList box control n A DirList Box control: – Displays an ordered, hierarchical list of directories and subdirectories n Most used property: – PathContains the current directory path Example: Path = dirExample.Path n Most used Event – ChangeHappens the directory selection is changed Example: Private Sub dirExample_Change() picOutput.Print dirExample.Path End Sub

16 16 FileList box control n A FileList Box control: – Locates and lists files in the directory specified by the Path property at run time n Most used properties: – FileNameContains the current selected file name – ListCountNumber of files listed – ListArray of file names in the list box – PathContains the current directory path – PatternContains a string that determine which files will be displayed (Example: *.doc only displays files with the.doc extension) n Most used Events – DblClick Happens whenever a file name is double-clicked. – PathChange Happens whenever the path changes Example: Private Sub filExample_ PathChange () picOutput.Print filExample.Path End Sub

17 17 Synchronizing Drive, Directory and File list boxes n Drive, Directory, and File list boxes are almost always used together to obtain a file name. – As such, it is important that their operation be synchronized to insure the displayed information is always consistent. n When the directory selection is changed (directory box Change event), you should update the displayed file names. Private Sub dirExample_Change() filExample.Path = dirExample.Path End Sub n When the drive selection is changed (drive box Change event), you should update the directory path Private Sub drvExample_Change() dirExample.Path = drvExample.Drive End Sub


Download ppt "List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)"

Similar presentations


Ads by Google