 A ListBox control displays a list of items and allows the user to select one or more  Drag from Toolbox to create this control on a form.

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Working with Intrinsic Controls and ActiveX Controls
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
ListBoxes The list box control allows the user to view and select from multiple items in a list. CheckedListBox control extends a list box by including.
Group Boxes and Panels Arrange components on a GUI Buttons and etc. can be placed inside a group box or panel. All these buttons move together when the.
More on lists, exceptions, loops and validation. You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 3 Tariq Aziz and Kevin Jones.
Compunet Corporation Programming with Visual Basic.NET GUI Chapter 3 Week 13 Tariq Aziz and Kevin Jones.
Adobe Forms THE FORM ELEMENT PANEL. Creating a form using the Adobe FormsCentral is a quick and easy way to distribute a variety of forms including surveys.
CST JavaScript Validating Form Data with JavaScript.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Chapter 7 Lists, Loops, and Printing Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
110 M - 1 ListBoxes & ComboBoxes Provide a list for the user to select from Various styles, choose based on –Amount of data to be displayed –Space available.
Copyright © 2014 Pearson Education, Inc. Chapter 5 Lists and Loops.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
CHƯƠNG 3 Finding, Filtering, and Formatting Data.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
© 2012 EMC Publishing, LLC Slide 1 Chapter 7 The Math Class  Includes shared methods that perform common math functions.  Math Class methods include:
Microsoft Office 2007 Access Chapter 3 Maintaining a Database.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 8: Chapter 5: Slide 1 Unit 8 List Boxes and the Do While Looping Structure.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 5 Lists, Loops, Validation, and More.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 5 Lists, Loops, Validation and More Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Week 6 Lists, Loops, Validation, and More. 2 Introduction This chapter covers the Visual Basic looping statements Do … While Do … Until For … Next It.
Lesson 4.  After a table has been created, you may need to modify it. You can make many changes to a table—or other database object—using its property.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
AdditionalControls 1. The MenuStrip 2 Double-click Let’s begin to design the menu bar for VB! Let’s begin to design the menu bar for VB! 3.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
Unit 6 Repetition Processing Instructor: Brent Presley.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
21/03/ Working with Controls Text and List Boxes.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 9: Chapter 5: Slide 1 Unit 9 Do Until and For… Next Loops Chapter 5 Lists,
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Microsoft Visual Basic 2008: Reloaded Third Edition
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Data Validation and Protecting Workbook
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Repeating Program Instructions
Variables and Arithmetic Operations
Chapter 5 Lists and Loops.
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Tony Gaddis Kip Irvine STARTING OUT WITH Visual Basic 2008
Lecture Set 9 Arrays, Collections, and Repetition
Presentation transcript:

 A ListBox control displays a list of items and allows the user to select one or more  Drag from Toolbox to create this control on a form

 The Items property holds an entire list of values from which the user may choose  The list of values may be established at run time or as part of the form design  To set list values in the form design: ◦ Select the list box in the Design window ◦ View properties & click the Items ellipsis button ◦ This property is a collection, a list of values ◦ Type each value on a separate line

 This property returns an integer with the number of entries stored in the Items property  Example of use:  The number of entries in the list can be assigned to an integer variable If lstEmployees.Items.Count = 0 Then MessageBox.Show("The list has no items!") End If numEmployees = lstEmployees.Items.Count

 The Items property values can be accessed from your VB code  Each item value is given a sequential index ◦ The first item has an index of 0 ◦ The second item has an index of 1, etc.  Example: name = lstCustomers.Items(2) ' Access the 3rd item value

 The index of the last item is always list.Items.Count-1  Reference to an index greater than Count-1 or less than zero throws an exception  An exception handler can trap this error  The variable ex captures the exception thrown Try strInput = lstMonths.Items(n).ToString() Catch ex as Exception MessageBox.show(ex.Message) End Try

 The SelectIndex property returns an integer with the index of the item selected by the user  If no item is selected, the value is set to -1 (an invalid index value)  Can use SelectIndex to determine if an item has been selected by comparing to -1  Example: If lstLocations.SelectedIndex <> -1 Then location = lstLocations.Items(lstLocations.SelectedIndex) End If

 Instead of using the SelectedIndex property as follows:  The SelectedItem property can be used to retrieve the value of a selected item as follows: If lstMonths.SelectedIndex <> -1 Then month = lstMonths.Items(lstMonths.SelectedIndex) End If If lstMonths.SelectedIndex <> -1 Then month = lstMonths.SelectedItem.ToString) End If

 Sorted is a boolean property  When set to true, values in the Items property are displayed in alphabetical order  When set to false, values in the Items property are displayed in the order they were added

 Items can be added to the end of a ListBox list in your VB code using the Add method  Format is ListBox.Items.Add(Item)  ListBox is the name of the control  Item is a string value to add to the Items property  Example: lstStudents.Items.Add("Sharon")

 Items can be added at a specific position of a ListBox in VB code using the Insert method ListBox.Items.Insert(Index, Item)  Index specifies position where Item is placed  Index is zero based similar to SelectedIndex property  Items that follow are “pushed” down  Example inserting "Jean“ as the 3 rd item lstStudents.Items.Insert(2, "Jean")

 ListBox.Items.RemoveAt(Index) ◦ Removes item at the specified index  ListBox.Items.Remove(Item) ◦ Removes item with value specified by Item  ListBox.Items.Clear() ◦ Removes all items in the Items property  Examples: lstStudents.Items.RemoveAt(2)‘remove 3 rd item lstStudents.Items.Remove(“Jean”)‘remove item Jean lstStudents.Items.Clear()‘remove all items

 ListBox.Items.Contains(Item) ◦ Returns true if Item is found in the collection  ListBox.Items.IndexOf(Item) ◦ Returns an integer with the index position of the first occurrence of Item in the collection  Examples: blnFound = lstMonths.Items.Contains(“March”) intIndex = lstMonths.Items.IndexOf(“March”)

Slide  The ListBox has a Multicolumn property ◦ Boolean property with default value of false ◦ If set to true, entries can appear side by side  Below, ColumnWidth is set to 30  Note the appearance of a horizontal scroll bar in this case

Slide  A form of ListBox with the list box properties and methods already discussed  One item at a time may be selected but many items in a Checked List Box can be checked  The CheckOnClick property determines how items may be checked ◦ False - user clicks item once to select it, again to check it ◦ True - user clicks item only once to both select it and check it

Slide  The GetItemChecked method returns true if the item at Index has been checked CheckedListBox.GetItemChecked(Index) Dim i as Integer Dim intCheckedCities as Integer = 0 For i = 0 to clbCities.Items.Count – 1 If clbCities.GetItemChecked(i) = True Then intCheckedCities += 1 End If Next i MessageBox.Show(“You checked “ & _ intCheckedCities.Tostring() & “ cities.”)

Slide  Both display a list of items to the user  Both have Items, Items.Count, SelectedIndex, SelectedItem, and Sorted properties  Both have Items.Add, Items.Clear, Items.Remove, and Items.RemoveAt methods  These properties and methods work the same with combo boxes and list boxes

Slide  A combo box also functions like a text box  The user may enter text into a combo box  Or the user may select the text from a series of list box type choices

Slide  If restricting the user to select items listed ◦ If empty space – use ListBox ◦ If limited space – use drop-down list ComboBox  If allowing user to select an item listed or enter an entirely new item ◦ If empty space – use simple ComboBox ◦ If limited space – use drop-down ComboBox

 When you code, you need to anticipate what the user is going to do with your code and what ways they can crash it  Some languages have error messages that you can capture ◦ Once captured you can display to the user an error message

Slide  Numbers are checked to ensure they are within a range of possible values ◦ For example, there are 168 hours in a week ◦ A person can’t work more than 168 hours a week  Values are checked for their “reasonableness” ◦ A person might possibly work 168 hours in a week ◦ However, this is highly improbable  Items selected from a menu or a set of choices are checked to ensure these options are available  Variables are checked for values that might cause problems, such as division by zero

 Empty input ◦ User hits enter before entering data  How would we test for this?  Incorrect Datatype ◦ User enters in a string for a number, etc.  Comparison against a list of acceptable values ◦ State abbreviations ◦ Zip codes

 String length ◦ State abreviation = 2 character strings ◦ How would we test for this?  Numbers in a reasonable range ◦ Hourly wages, salary amounts, # of hours  Dates in reasonable ranges ◦ There is no February 30 th  Time measurements checked