VB List(Of type) A List can be thought of as an array that automatically adjusts its size as elements are added and removed A List may hold only objects.

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.
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)
Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
Generics, Lists, Interfaces
Coding ADO.Net DataSet Objects ISYS 512. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Lecture Roger Sutton CO331 Visual Programming 19: Simple file i/o Exceptions – Error handling 1.
VB.Net Loops.
1 Prototyping for HCI Spring 2004 (Week 7) Jorge A. Toro.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Arrays. Declaring a Array With subscript: –Dim numbers(2) as Integer –Using variable as subscript: Dim arrayIndex as Integer = 10 Dim myArray(arrayIndex)
List-based Controls. Slide 2 Introduction There are several controls that work with lists ComboBox ListBox CheckedListBox.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Using Arrays and File Handling
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
ListBoxes Monday, March 21, 2011 Roxana Gheorghiu.
© 1999, by Que Education and Training, Appendix A, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
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.
 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.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
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.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
05/02/ Records. 205/02/2016 Learning Objectives State: The difference between records and arrays. The difference between records and arrays. How.
Unit 6 Repetition Processing Instructor: Brent Presley.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
21/03/ Working with Controls Text and List Boxes.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Click to edit Master text styles Stacks Data Structure.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Reading & writing to files
Apply Procedures to Develop Menus, List Box and Combo Box Objects
IS 350 Loops.
VB.NET Using Database.
CIS16 Application Development and Programming using Visual Basic.net
Lecture Set 10 Windows Controls and Forms
Fonts, TabControl, ListBox
Dictionary Builder Part 4 Loading Files.
To understand what arrays are and how to use them
Just Basic Lessons Mr. Kalmes.
Lecture Set 9 Arrays, Collections, and Repetition
Presentation transcript:

VB List(Of type) A List can be thought of as an array that automatically adjusts its size as elements are added and removed A List may hold only objects of type Because it automatically varies in size, a List is more flexible than an array Elements can be accessed by index just as with an array: list(i)

List Methods Add(obj) : Adds obj to the list Remove(obj) : Removes obj from the list RemoveAt(i) : Removes the object from position i of the list Clear() : Clears the list Contains(obj) : Determines whether obj is in the list or not

List Methods (Cont'd) Insert(i, obj) : Inserts obj at position i of the list Reverse() : Reverses the order of the list IndexOf(obj) : Returns the index of obj ToArray() : Returns the elements of the list in an array of type

List Properties Count : Number of elements in the list (read-only) Item(i) : Gets or sets the element at position i in the list –Equivalent to list(i) : list(i) = value value = list(i)

List Examples Dim SomeList as List(Of SomeData) For Each s As SomeData In SomeList Console.WriteLine(s.ToString) Next For i As Integer = 0 To SomeList.Count Console.Writeline(SomeList(i)) Next

Lists as Data Sources Lists of Class can be connected to a ListBox control as a data source You must identify: –the Class string property to display in the ListBox –the Class value to return when a ListBox item is selected –the List to act as a data source

Lists as Data Sources (Cont'd) To bind a List to a ListBox: ListBox.DisplayMember = Class.property ListBox.ValueMember = Class.property ListBox.DataSource = List To extract values from the ListBox: index = ListBox.SelectedIndex value = ListBox.SelectedValue ListItem = ListBox.SelectedItem

Lists as Data Sources (Cont'd) The ListBox must be updated when the List is updated: ListBox.DataSource = Nothing ListBox.DataSource = List The display and value members do not have to be updated This seems kludgy - but it works

ListBox Data Source Example The Province class has two properties: Code (ex: "ON") and Name (ex: "Ontario") Define and fill a List of Province: Dim Provinces = List(Of Province) Bind the list to a ListBox lbProv : lbProv.DisplayMember = "Code" lbProv.ValueMember = "Name" lbProv.DataSource = Provinces

ListBox Data Source Example An element of the province list can be accessed by index, as an item (Province object), or just its name can be accessed

ListBox Data Source Example Set a temporary variable: Dim p as Province Index access: p = Provinces(lb.SelectedIndex ) Item access: p = CType(lb.SelectedItem, Province) Value (Name) access: n As String = lb.SelectedValue

List Inheritance User-defined classes can inherit from List Such a class has all the capabilities of List plus whatever extra methods and properties the user may define Define: Public Class SomeList Inherits List(Of SomeClass)

List Inheritance (Cont'd) SomeList now has access to all List methods and properties

List Inheritance Example Imports System.IO Public Class SubjectsList Inherits List(Of Subject) Public Sub New(ByVal fileName As String) Dim fileHandle As StreamReader = File.OpenText(fileName) Do While fileHandle.Peek <> -1 Dim s As Subject = New Subject(fileHandle) Me.Add(s) Loop fileHandle.Close() End Sub End Class

List Inheritance Example Sample uses of a Subjects class: Dim Subjects as SubjectList = New SubjectList( fileName ) … Subjects.Add( New Subject( code, desc ) ) … tbCode.Text = Subjects(i).Code … Subjects.RemoveAt(i)