St. Ambrose CSCI 480 - Lists, Loops, and Printing

Unformatted text preview:

Chapter 7 Lists, Loops, and PrintingList Boxes and Combo BoxesSlide 3Slide 4Slide 5List Boxes and Combo Boxes cont.The Items CollectionFilling a ListPowerPoint PresentationSlide 10Using the Items.Add MethodUsing the Items.Insert MethodThe SelectedIndex PropertyThe Items.Count PropertyReferencing the Items CollectionReferencing the Items Collection cont.Removing an Item from a ListClearing a ListList Box and Combo Box EventsThe Three Programming StructuresThe while and do/while LoopsThe while and do/while Loops cont.Slide 23Slide 24The bool Data Type Revisitedfor Loopsfor Loops cont.Slide 28Making Entries Appear SelectedSending Information to the PrinterThe PrintDocument ControlSetting Up the Print OutputPrintDocument ControlPrintDocument Control EventsThe Graphics PageUsing the DrawString MethodSetting the X and Y CoordinatesPrinting the Contents of a List BoxPrinting cont.Printing Multiple PagesChapter 7Lists, Loops, and PrintingProgramming in C# .NETProgramming in C# .NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2List Boxes and Combo BoxesBoth can be used for user to select from a Both can be used for user to select from a list of itemslist of itemsCombo box has the additional capability Combo box has the additional capability of allowing the user to type into a text boxof allowing the user to type into a text box3List Boxes and Combo BoxesTypes of list boxes and combo boxesTypes of list boxes and combo boxesSimple list boxesSimple list boxesCan only choose one itemCan only choose one itemChecked list boxes Checked list boxes Can select multiple itemsCan select multiple itemsSimple combo boxesSimple combo boxesHas a text box where user can type itemHas a text box where user can type itemDrop-down combo boxesDrop-down combo boxesLike the simple list but user can type text into a text boxLike the simple list but user can type text into a text boxDrop-down listsDrop-down listsNo text box displayed at top user cannot type new textNo text box displayed at top user cannot type new text4List Boxes and Combo Boxes5List Boxes and Combo BoxesList boxes and combo boxes have many common List boxes and combo boxes have many common properties and operate similarlyproperties and operate similarlyCombo box control has a Combo box control has a DropDownStyle propertyDropDownStyle property to determine if list box has a text box for user entry to determine if list box has a text box for user entry and whether list will drop downand whether list will drop downDrop-Down and Simple Combo style have text Drop-Down and Simple Combo style have text boxesboxesDrop-List has no text boxDrop-List has no text box6List Boxes and Combo Boxes cont.Scroll bars are added automatically if the box is too Scroll bars are added automatically if the box is too small to display all items in listsmall to display all items in listSelect list style based on Select list style based on space available space available how box should operatehow box should operateList box displays Name property in controlList box displays Name property in controlCombo box displays Text property in controlCombo box displays Text property in controlList box Text property available only at run timeList box Text property available only at run time7The Items CollectionList of items in a list box or combo box is a List of items in a list box or combo box is a collectioncollectionCollections are objects with properties and Collections are objects with properties and methodsmethodsItems collectionItems collection used to add items, remove items, used to add items, remove items, refer to items, count the items, and clear the listrefer to items, count the items, and clear the listRefer to items in collection by an indexRefer to items in collection by an index which which starts at zerostarts at zeroRefer to first item in the Items collection as Refer to first item in the Items collection as Items[0]Items[0]8Filling a ListUse Items property at design time if list Use Items property at design time if list contents are known and will not changecontents are known and will not changeClick on ellipses button next to Items Click on ellipses button next to Items property to open String Collection Editorproperty to open String Collection EditorUse String Collection Editor to add items to Use String Collection Editor to add items to listlistTo add items during execution, use the To add items during execution, use the Items.AddItems.Add or or Items.InsertItems.Insert method method91011Using the Items.Add MethodGeneral FormGeneral FormObject.Items.Add(ItemValue);Object.Items.Add(ItemValue);New item added to end of the listNew item added to end of the listIf the control’s If the control’s SortedSorted property set to property set to truetrue places places item alphabetically in listitem alphabetically in listMust use the Must use the AddAdd method to add value user types in method to add value user types in text box of combo box to the listtext box of combo box to the listExample: Example: cboCoffee.Items.Add(cboCoffee.Text);cboCoffee.Items.Add(cboCoffee.Text);12Using the Items.Insert MethodChoose location for a new item in the list by Choose location for a new item in the list by specifying the index positionspecifying the index positionGeneral Form General Form Object.Items.Insert(IndexPosition, ItemValue);Object.Items.Insert(IndexPosition, ItemValue);Index is zero basedIndex is zero basedDo not set the list control’s Sorted property to Do not set the list control’s Sorted property to truetrue if if using the Insert methodusing the Insert methodExample: Example: lstSchools.Items.Insert(0,”Harvard”)lstSchools.Items.Insert(0,”Harvard”);;13The SelectedIndex PropertySelectedIndexSelectedIndex property property contains index number contains index number of item the user selects (highlights)of item the user selects (highlights)If SelectedIndex is set to negative 1 (-1)If SelectedIndex is set to negative 1 (-1)Example: Example: lstCoffeeTypes.SelectedIndex = 3;lstCoffeeTypes.SelectedIndex = 3; //Select fourth item in list //Select fourth item in list14The Items.Count PropertyCountCount property property of Items collection contains of Items collection contains number of items in the listnumber of items in the listItems.Count is always one more than the Items.Count is


View Full Document

St. Ambrose CSCI 480 - Lists, Loops, and Printing

Download Lists, Loops, and Printing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lists, Loops, and Printing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lists, Loops, and Printing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?