Lecture Set 10 Windows Controls and Forms

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.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
1 Visual Basic Programming II Lecture 3 MIS233 Instructor – Larry Langellier.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Microsoft Visual C#.NET: From Problem Analysis to Program Design1 Chapter 9 Programming Based on Events Microsoft Visual C#.NET: From Problem Analysis.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
Programming Based on Events
VB Default Controls List Box, Combo Box
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.
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
Programming Based on Events
List-based Controls. Slide 2 Introduction There are several controls that work with lists ComboBox ListBox CheckedListBox.
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.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
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.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
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.
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.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
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.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Unit 6 Repetition Processing Instructor: Brent Presley.
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.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 9 Programming Based on Events
INF230 Basics in C# Programming
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Computing with C# and the .NET Framework
© 2016, Mike Murach & Associates, Inc.
ASP.NET Web Controls.
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
IS 350 Loops.
Repeating Program Instructions
Programming Based on Events
Microsoft Visual Basic 2005: Reloaded Second Edition
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
The List Box Control Items can be placed into the list at design time or run time The Sorted property causes items in the list to be sorted automatically.
CIS16 Application Development and Programming using Visual Basic.net
CIS 16 Application Development Programming with Visual Basic
CIS16 Application Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Module 8: Creating Windows-based Applications
Based on Murach Chapter 10
Chapter 10 Accessing Database Files
Lecture Set 9 Arrays, Collections, and Repetition
Presentation transcript:

Lecture Set 10 Windows Controls and Forms Part A – Repetition Controls: List and Combo Boxes and DataViewGrids

Objectives To understand the mechanics and use of the list boxes and combo boxes both of which are repetition based controls Understand how the DataViewGrid control works To be able to design and code a form using any of the controls introduced to date. 8/22/2013 11:30 AM

Objectives (continued) Given a form with two or more controls, set the tab order of the controls Given the specifications for an application that displays custom or standard dialog boxes, design and code the application Describe how you can use the DialogResult enumeration and the Tag property to pass data between a form and a custom dialog box. Describe how you can use the FormClosing event to stop a form from closing. 8/22/2013 11:30 AM

Hierarchical Organization of the ListBox and ComboBox Controls 8/22/2013 11:30 AM

Sample Form with Five Control Types

The System.Windows. Forms.ListControl class The Items property is a collection Each object is an item in the list The SelectedIndex property contains the 0-based index value of the selected item The value is -1 if no item is selected The SelectedItem property contains a reference to the selected item itself The value is Nothing of no item is selected The ClearSelection method deselects all selected items Windows fires the SelectedIndexChanged event when an item is selected 8/22/2013 11:30 AM

Introduction to the ComboBox Control The ComboBox control displays a list of items from which the end user selects one item The DropDownStyle property defines the visual appearance of the ComboBox DropDown Simple DropDownList 8/22/2013 11:30 AM

Introduction to the ListBox Control The ListBox control is similar to the ComboBox control Except -- The visible region does not drop down The SelectedItems property returns a collection of the selected items The SelectionMode property defines whether the user can select one item or many items The ClearSelected method clears the selected items 8/22/2013 11:30 AM

Working with the ComboBox and ListBox Controls Common operations Items must be added to the list Conditional actions must be performed as the end user selects list items Items must be selectable programmatically 8/22/2013 11:30 AM

Adding Items to a ComboBox or ListBox Items can be added at design time using the String Collection Editor Items can be added at run time by calling the Add method as follows: for (int count = 1; count <= 20; count++) { lstDemo.Add("Item " + count.ToString()); } // end for 8/22/2013 11:30 AM

The String Collection Editor Dialog Box 8/22/2013 11:30 AM

Working with the Selected Item When the end user selects an item, a SelectedIndexChanged event fires Two properties are of interest The SelectedItem property references the object currently selected The SelectedIndex property stores the 0-based index of the currently selected item 8/22/2013 11:30 AM

Working with the Selected Item (Example) Display information about the selected item private void cboSingleSelect_SelectedIndexChanged (object sender, System.EventArgs e) { lblSelectedComboBoxItem.Text = cboSingleSelect.SelectedItem.ToString(); } // end SelectIndexChanged 8/22/2013 11:30 AM

Selecting an Item Programmatically (Examples) Select the first item in the combo box named cboSingleSelect cboSingleSelect.SelectedIndex = 0; Clear the selected item cboSingleSelect.SelectedIndex = -1; 8/22/2013 11:30 AM

The DataGridView Control The DataGridView control displays data as a 2-dimensional grid made up of rows and columns It is very much like a special case of a 2-D array The intersection of a row and column is called a cell It can operate in two modes The DataGridView can be bound to a data source It can operate in an unbound mode Rows and columns are added manually 8/22/2013 11:30 AM

DataGridView Control Instance Displaying a Multiplication Table

Working with the DataGridView Control Steps to populate the grid Add the columns Add the rows The columns must be added before the rows are added Populate the cells It's possible to delete existing rows 8/22/2013 11:30 AM

Adding Columns to the DataGridView The Add method of the Columns collection adds a column as follows: dgvDemo.Columns.Add("Column1", "VisibleText"); The first argument contains the column name The second argument contains the column's caption Columns are added to the end of the list 8/22/2013 11:30 AM

Adding Rows to the DataGridView Without arguments, the Add method adds one row dgvDemo.Rows.Add(); The Add method will add multiple rows when called with an Integer argument dgvDemo.Rows.Add(20); 8/22/2013 11:30 AM

Referencing and Populating Individual Grid Cells The following statements reference the first cell in the first row: DataGridViewCell CurrentCell = dgvDemo.Rows(0).Cells(0); dgvDemo.Rows(0) references the first row in the collection Cells(0) references the first cell in the first row The data type of a cell is DataGridViewCell 8/22/2013 11:30 AM

Storing and Retrieving Cell Values The Value property of the DataGridViewCell stores the cell's value Example: CurrentCell.Value = 42; txtDemo.Text = currentCell.Value.ToString(); 8/22/2013 11:30 AM

Deleting Rows from the DataGridView Like most collections, the RemoveAt method removes a row The argument contains the 0-based index value Example to remove the first row: dgvDemo.Rows.RemoveAt(0); 8/22/2013 11:30 AM

Using a Loop to Examine Cells The Rows collection has a Count property containing the number of elements (rows) Thus, a For loop can be used to examine each row Examine the first column (cell) in each row double total = 0; for (int currentRow = 0; currentRow < gvDemo.Rows.Count; currentRow++) { total += dgvDemo.Rows(currentRow).Cells(0).Value; } // end for 8/22/2013 11:30 AM

1/16/2019 6:09 AM

Common Members of List Box and Combo Box Controls (continued) 1/16/2019 6:09 AM

1/16/2019 6:09 AM

Code to Loading Combo Boxes 1/16/2019 6:09 AM

Clearing and Reloading a Combo Box 1/16/2019 6:09 AM

Retrieving Information from a Combo Box 1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

Adding Forms 1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

DialogResults and Tags 1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

More on the Message Box Class 1/16/2019 6:09 AM

Displaying a Dialog Box 1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

Code for the Customer Form (continued) private void SaveData() { cboNames.SelectedIndex = -1; lblPayment.Text = "“; isDataSaved = true; cboNames.Select(); } // end SaveData 1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM

1/16/2019 6:09 AM