Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

Chapter 5

Using Controls with Looping Statements

Looping Statements
- The looping statement is a program instruction that repeats some statement or
sequence of statements in a specified number of times.
- Allows a set of instructions to be performed all over and over again until a certain
condition is reached, met, proven or tested as false or true.
- Allows us to execute one or more lines of code repetitively.

Three Types of Looping Statements


1. for loop and for each loop
2. while loop
3. do/while loop

The syntax of the for loop statement is:

for (initialization; condition; increment/decrement){


statement(s); statements that do something repetitively (body of the loop)
}

initialization- first value where the loop starts


- usually starts at zero when the looping statement is used to generate arrays.

condition- is where we say when to stop the looping process.


- The loop continues to execute so long as the condition which the program is evaluating (or
checking) is true.
- Once it is no longer true, the loop terminates.

increment-where we say by how much to increase the loop counter on each pass through the loop.

decrement- where we say by how much to decrease the loop counter on each pass through the loop.

The syntax of the for each loop statement is:

foreach (element in group) {


statement(s)
}

Example of how to use the for each looping statement:

foreach(Control oObject in Controls){


statement(s)
}

foreach loop- repeats a group of statements for each element in a collection of objects or in an array
instead of repeating the statements in a specified number of times.
- especially helpful if we don’t know how many elements are in a collection

The syntax of the while loop statement is:

initialization;

while (condition) {
statement(s);
increment/decrement;
}

The syntax of the do-while statement is:

initialization;

do {
statement(s);
increment/decrement;
} while (condition);

Using List Boxes

List Box- is an ideal way of presenting a list of data or choices to the user.
- In fact, it is an effective way to present a large number of choices or data to the user in a limited
amount of space.

- The user can browse the data in the list box or select one or select one or more items for
processing purposes.

- The process could be transferring the chosen items from the list box to a cart (or a transfer of
items from one list box to another)

- The transfer can also be from a list box to a text box or to a combo box.

For example, in the computerized grocery store system, the items could be the products which the
buyer can select and buy.

- By default, the items in the list box are displayed vertically in a single column, although we can
set up multiple columns too.
- When the list of items or data is too long for the list box, the Visual C# system will simply add a
vertical scroll bar. With this, the user can then scroll up and down or left or right through the list
of items.

Example 1:

Design and develop a simple looping statement program that generates the given sequence
numbers using the for statement.

Coding Solution:

private void button1_Click(object sender, EventArgs e)


{
listBox1.BeginUpdate();
int nCounter;

for (nCounter=1;nCounter<=5;nCounter++)
{

listBox1.Items.Add(“Loop “ + nCounter.ToString());
}
listBox1.EndUpdate();
}

Add() method- used to add items in the list box


BeginUpdate() method- simply to turn off the visual updating of the list box
EndUpdate() method- resumes the visual updating of the list box

Example 2:

Design and develop a simple looping statement program that generates the given sequence
numbers using the do-while loop syntax. (1 to 5).

Coding Solution:
private void button1_Click(object sender, EventArgs e)
{
listbox1.BeginUpdate();
int nCounter=1;
do {
listBox1.Items.Add(“Loop “ + nCounter.ToString());
nCounter++;
} while (nCounter<=5);
listBox1.EndUpdate();
}
Example 3:

Design and develop a simple looping statement program that generates the given inverse
sequence numbers using the for statement (5 to 1).

Coding Solution:

private void button1_Click(object sender, EventArgs e)


{
listBox1.BeginUpdate();
int nCounter;

for (nCounter=5;nCounter>=1;nCounter- -)
{
listBox1.Items.Add(“Loop “ + nCounter.ToString());
}
listBox1.EndUpdate();
}

Example 4:
Design and develop a simple looping statement program that generates the given inverse
sequence numbers using the do-while loop syntax. (5 to 1).

Coding Solution:
private void button1_Click(object sender, EventArgs e)
{
listbox1.BeginUpdate();
int nCounter=5;
do {
listBox1.Items.Add(“Loop “ + nCounter.ToString());
nCounter--;
} while (nCounter>=1);
listBox1.EndUpdate();
}

Simple Array

Array- a special type of variable which can contain or hold one or more values of the same data
type with reference to only one variable name.
- In other words, the array variable has a common name identifier and can hold many
values at the same time, provided they have the same data type.
- An array variable can be distinguished through a pair of square brackets [] and on
specified number inside them which is called an index.
- In case of enumerated arrays, we can distinguish its declaration through a pair of curly
brackets: { }.

Syntax of one dimensional array:

Data_type ArrayName[ ]

Examples of Array Declaration:

Example 1:

String [] strIDArray=new String[5];

strIDArray[0]=”Monkey”;
strIDArray[1]=”Zebra”;
strIDArray[2]=”Elephant”;
strIDArray[3]=”Eagle”;
strIDArray[4]=”Crocodile”;

or this way (Enumerated Array format):

String[] strIDArray={“Monkey”, “Zebra”, “Elephant”, “Eagle”, “Crocodile”};

Example 2:

int [] intIDArray=new int[5];

intIDArray[0]=6;
intIDArray[1]=12;
intIDArray[2]=14;
intIDArray[3]=9;
intIDArray[4]=4;

or this way (Enumerated Array format):

int [] intIDArray {6, 12,14,9,4};


Example 5:

Design and develop a simple program that demonstrates how to use the for each loop syntax
that display each item in an array with a string data.

Coding Solution:

private void button1_Click(Object sender, EventArgs e)


{
listBox1.BeginUpdate();
String [] strIDArray= new String [5];

strIDArray[0]=”Monkey”;
strIDArray[1]=”Zebra”;
strIDArray[2]=”Elephant”;
strIDArray[3]=”Eagle”;
strIDArray[4]=”Crocodile”;

foreach (String strArrayItem in strIDArray)


{
listBox1.Items.Add (strArrayItem.ToString());
}

listBox1.EndUpdate();
}

Example 6:

Design and develop a simple program that demonstrates how to use the for each loop syntax
that display each item in an array with an integer data.

Coding Solution:

private void button1_Click(object sender, EventArgs e)


{
listBox1.BeginUpdate();
int [] intIDArray= new int [5];

intIDArray[0]=6;
intIDArray[1]=12;
intIDArray[2]=14;
intIDArray[3]=9;
intIDArray[4]=4;

foreach (int intArrayItem in intIDArray)


{
listBox1.Items.Add(intArrayItem.ToString());
}
listBox1.EndUpdate()
}

Example 7:

Design and develop a simple program that demonstrates how to use the for each loop syntax
that counts how many objects are there in a Form.

Coding Solution:

private void button1_Click(object sender, EventArgs e)


{
int nIterate=0;
foreach(Control oObject in Controls) {
nIterate++;
}

textBox1.Text=nIterate.ToString();
}

Example 8:

Design and develop a simple program that demonstrates how to preload a collection of items to
a list box at run time.

private void Form1_Load (object sender, EventArgs e)


{
listBox1.Items.Add(“Milan”);
listBox1.Items.Add(“Paris”);
listBox1.Items.Add(“Madrid”);
listBox1.Items.Add(“Tokyo”);
listBox1.Items.Add(“Manila”);
listBox1.Items.Add(“New Delhi”);
listBox1.Items.Add(“Kuala Lumpur”);
listBox1.Items.Add(“San Francisco”);
}

Example 9:

Design and develop a simple program that demonstrates how to preload the list box with items.
When the user chooses an item at the list box by double-clicking it, that particular item will be displayed
at the text box.
Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Text=””;
textBox1.Text=””;
//Add items to the list box

listBox1.Items.Add(“Chicken”);
listBox1.Items.Add(“Beef”);
listBox1.Items.Add(“Pork”);
listBox1.Items.Add(“Vegetables”);
listBox1.Items.Add(“Fish”);
listBox1.Items.Add(“Squids”);
listBox1.Items.Add(“Noodles”);
listBox1.Items.Add(“Fruits”);
}

private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)


{
textBox1.Text=””;
textBox1.Text=ListBox1.Text;
}

Example 10:

Design and develop a simple program that demonstrates how to preload a collection of items into the
list box as well as adding an item into the list box which is entered by the user in the text box. The
program also will be able to remove all the items one by one, starting from the top down to the bottom.

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Items.Add(“Item 1”);
listBox1.Items.Add(“Item 2”);
listBox1.Items.Add(“Item 3”);
listBox1.Items.Add(“Item 4”);
textBox1.Text=””;
}

private void button1_Click(object sender, EventArgs e)


{
listBox1.Items.Add(textBox1.Text);
textBox1.Text=””;
textBox1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
if(listBox1.Items.count==0)
MesageBox.Show(“No more Item!”);
else
listBox1.Items.RemoveAt(0);
}

Item.Count – the property use to determine the number of items in the list box.
- If it is equals to zero , then the list box is already empty.

Example 11:

Design and develop a simple program that demonstrates how to preload a collection of items
into the List box. The user should be able to remove a selected item on the list, one at a time. When the
user selects by clicking an item at the List box, that particular item must be deleted from the displayed
list.

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Items.Add(“sizzling beef”);
listBox1.Items.Add(“pork tonkatsu”);
listBox1.Items.Add(“chicken torikatsu ”);
listBox1.Items.Add(“fish tempura”);
listBox1.Items.Add(“miso soup”);
listBox1.Items.Add(“coffee jelly”);
listBox1.Items.Add(“yakiudon”);
listBox1.Items.Add(“gyoza”);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)


{
listBox1.Items.Remove(listBox1.SelectedItem);
}

Items.Remove- remove the selected item from the list box


SelectedItem- to get exactly the currently selected item

Example 12: Highlight first an item before confirming to delete it using a button

Design and develop a simple program that demonstrates how to preload a collection of items
into the list box. The program should be able to remove a selected item on the list, once at a time but
with a confirmation using a button.

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Items.Add(“sizzling beef”);
listBox1.Items.Add(“pork tonkatsu”);
listBox1.Items.Add(“chicken torikatsu ”);
listBox1.Items.Add(“fish tempura”);
listBox1.Items.Add(“miso soup”);
listBox1.Items.Add(“coffee jelly”);
listBox1.Items.Add(“yakiudon”);
listBox1.Items.Add(“gyoza”);
}

private void button1_Click(object sender, EventArgs e)


{
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}

Example 13: Displaying selected item into another list box

Design and develop a simple program that demonstrates how to preload a collection of items
into the list box. The program should be able to display one or more selected items in another list box.
When the user selects by clicking an item at the list box 1, that particular item must be displayed at the
list box 2.

Coding solution:

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Items.Add(“Hamburger”);
listBox1.Items.Add(“Cheeseburger”);
listBox1.Items.Add(“Chickenburger”);
listBox1.Items.Add(“Mashed Potatoe”);
listBox1.Items.Add(“Spaghetti”);
listBox1.Items.Add(“Honeybun”);
listBox1.Items.Add(“Macaroni Salad”);
listBox1.Items.Add(“Cherry Pie”);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)


{
//Add item to list Box 2
listBox2.Items.Add(ListBox1.Text);
}
Example 13: Transferring an item from one list box to another

Design and develop a simple program that demonstrates how to preload a collection of
items into the list box. The program should be able to transfer one or more selected items on
another list box.

Coding Solution:

private void Form1_Load(object sender,EventArgs e)


{
listBox1.Items.Add(“Java”);
listBox1.Items.Add(“C++”);
listBox1.Items.Add(“Perl”);
listBox1.Items.Add(“Basic”);
listBox1.Items.Add(“FoxPro”);
listBox1.Items.Add(“Pascal”);
listBox1.Items.Add(“COBOL”);
listBox1.Items.Add(“HTML”);
listBox1.Items.Add(“XML”);
listBox1.Items.Add(“Fortran”);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)


{
//Add the item to the other list box
listBox2.Items.Add(listBox1.Text);
listBox2.Items.Remove(listBox2.Text);
//Remove the item from this list box
listBox1.Items.Remove (listBox1.SelectedItem);
}

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)


{
//Add the item to the other list box
listBox1.Items.Add(listBox2.Text);
listBox1.Items.Remove(listBox1.Text);
//Remove the item from this list box
listBox2.Items.Remove (listBox2.SelectedItem);
}
Example 14: We will know what particular item is currently selected by the user at the List box.
Then we will confirm it by displaying a description of that particular at the text box.

Design and develop a simple program that demonstrates how to preload a collection of items
into the List box. The program should be able to get the value of the currently selected item in
the list box. The selected item should display its corresponding description at the text box.

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
textBox1.Text=””;
listBox1.Items.Add(“Germany”);
listBox1.Items.Add(“Philippines”);
listBox1.Items.Add(“Singapore”);
listBox1.Items.Add(“Japan”);
listBox1.Items.Add(“Alaska”);
listBox1.Items.Add(“California”);
listBox1.Items.Add(“Italy”);
listBox1.Items.Add(“France”);
listBox1.Items.Add(“Alabama”);
listBox1.Items.Add(“Brazil”);
listBox1.Items.Add(“Venezuela”);
}

private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)


{
if(listBox1.Text==”German”)
{
textBox1.Text=””;
textBox1. Text=”Germany is in Europe”;
}

else if(listBox1.Text==”Philippines”)
{
textBox1.Text=””;
textBox1. Text=”Philippines is in Asia”;
}

else if(listBox1.Text==”Singapore”)
{
textBox1.Text=””;
textBox1. Text=”Singapore is in Asia”;
}

else if(listBox1.Text==”Japan”)
{
textBox1.Text=””;
textBox1. Text=”Japan is in Asia”;
}

else if(listBox1.Text==”Alaska”)
{
textBox1.Text=””;
textBox1. Text=”Alaska is in North America”;
}

else if(listBox1.Text==”California”)
{
textBox1.Text=””;
textBox1. Text=”California is in North America”;
}

else if(listBox1.Text==”Italy”)
{
textBox1.Text=””;
textBox1. Text=”Italy is in Europe”;
}

else if(listBox1.Text==”France”)
{
textBox1.Text=””;
textBox1. Text=”France is in Europe”;
}

else if(listBox1.Text==”Alabama”)
{
textBox1.Text=””;
textBox1. Text=”Alabama is in North America”;
}

else if(listBox1.Text==”Brazil”)
{
textBox1.Text=””;
textBox1. Text=”Brazil is in Latin America”;
}

else if(listBox1.Text==”Venezuela”)
{
textBox1.Text=””;
textBox1. Text=”Venezuela is in Latin America”;
}

Example 15: Adding, Removing, and Clearing an item in the list box

Design and develop a simple program that should apply the Items.Add,
Items.Remove, and Clear methods with the SelectedIndex and Items.Count properties
to add, remove and clear the list entries in the List box at run time.

Button Objects Property Setting


Add Button Name btnAdd
Text Add

Delete Button Name btnDelete


Text Remove

Clear Button Name btnClear


Text Clear

Exit Button Name btnExit


Text Exit

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
textBox1.Text=””;
textBox2.Text=””;
//we have to disable the Add button by default to prevent it from
//adding any blank spaces to the list box
//it can only add an item if there is a Text Change event happened at the Text Box 1.
//Meaning, the user is now inputting data in the Text Box 1.
btnAdd. Enabled =false;
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)


{
btnDelete.Enabled=listBox1.SelectedIndex !=-1;
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
int nLen;
nLen=textBox1.Text.Length;
if(nLen>0)
{
//Enable the add button if at least
//one character in the text box 1
btnAdd.Enabled=true;
}
}

private void btnAdd_Click(object sender, EventArgs e)


{
//Add to the List box
listBox1.Items.Add(textBox1.Text);
//clear the text box
textBox1.Text=””;
textBox1. Focus();
//Display the number of items to the text box 2
textBox2.Text=Convert.ToString(listBox1.Items.Count);
//We need to disable the Add button after we click it so that
//the space character of the TextBox1 cannot be allowed to be added to the
//ListBox. Only in this way we can ensure that no blank spaces
//can be added to the ListBox
btnAdd.Enabled=false;
}

private void btnDelete_Click(object Sender, EventArgs e)


{
int Ind;
//get the index
Ind=listBox1.SelectedIndex;
if(Ind>=0)
{
//remove it from the list box
listBox1.Items.RomoveAt(Ind);
//Display the number of items to the text box 2.
textbox2.Text=Convert.ToString(listBox1.items.Count;
else
{
//Generate a warning sound

MessageBox.Show(“No more items left to erase!”);


}
//disable button if no more items on the list box.
btnDelete.Enabled=(listBox1.SelectedIndex!=-1);

private void btnClear_Click(object sender, EventArgs e)


{
//Empty the list box
listBox1.Items.Clear();
//disable delete button
btnDelete.Enabled=false;
textBox2.Text=Convert.ToString(listBox1.Items.Count);
}

private void btnExit_Click(object sender, EventArgs e)


{
this.Close();
}
Example 16: Selecting two or more items in the list box at once

Design and develop a simple program that should be able to select two or more
items in the list box at once and be able to transfer the collection of selected items to
another list box simultaneously. Press Shift and arrow keys to select multiple items.

Objects Property Setting


List Box 1 Name ListBox1
SelectionMode MultiExtended

Transfer Button Name btnTransfer


Text Transfer

Clear Button Name btnClear


Text Clear

Exit Button Name btnExit


Text Exit

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
listBox1.Items.Add(“January”);
listBox1.Items.Add(“February”);
listBox1.Items.Add(“March”);
listBox1.Items.Add(“April”);
listBox1.Items.Add(“May”);
listBox1.Items.Add(“June”);
listBox1.Items.Add(“July”);
listBox1.Items.Add(“August”);
listBox1.Items.Add(“September”);
listBox1.Items.Add(“October”);
listBox1.Items.Add(“November”);
listBox1.Items.Add(“December”);
//Pre-select a collection of items

listBox1.SetSelected(1, true);
listBox1.SetSelected(3, true);
listBox1.SetSelected(5, true);
}

private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)


{
//Click the transfer button
btnTransfer.Enabled=true;
}

private void btnTransfer_Click(object sender, EventArgs e)


{
listBox1.BeginUpdate();
foreach (String sItem in ListBox1.SelectedItems)
{
listBox2.Items.Add(sItem);
}
listBox1.EndUpdate();
btnClear.Enabled=true;
}

private void btnClear_Click(object sender, EventArgs e)


{
listBox2.Items.Clear();
btnClear.Enabled=false;
}

private void btnExit_Click(object sender, EventArgs e)


{
this.Close();
}

Warning: Don’t forget to set the Multi-Select property of list box 1 with the 2-Extended
setting. It is very important, otherwise, our program will not run on our intended
purpose.
Using Combo Box

Combo box- derived from the words ”combination box”, meaning it combines the
features of both a text box and a list box.
- Allows the user to select an item either by typing text into the combo box, or by
selecting a predefined item from the list.
- Allows us to select a predefined item from a list or to enter a new item which is
not in the list.
- Like a list box, a combo box presents a list of choices to the user.
- If the number of items exceeds what can be displayed in the combo box, scroll
bars will automatically appear on the control.

Advantages of the Combo Box over List Box

A potential problem with a list box is that in some situations, you are stuck with
the entries displayed. You can’t directly edit an item in the list or select an entry that’s
not already there. Though it’s a big advantage compared to combo box is that if you
want to restrict the user, then a list box is best suited in this situation. While the
strength of a combo box is that it takes less room on a form than a normal list box,
because the full list is not displayed until the user clicks the down arrow. In other words,
a combo box can easily fit in a small space where a list box would not fit. Moreover, a
combo box contains an edit field, so choices not in the list can be typed in this field by
the user. In most program development situations, a combo box is appropriate when
there is a list of suggested choices, and a list box is appropriate when you want to limit
input to what s on the list.

Example 17:
Design and develop a simple application system that preloads a combo box with
items. The user can select an item from the list to be displayed at the text box. When
the user selects an item at the Combo box by clicking on it, this item will be displayed at
the text box. The user must click the down arrow (found at the right corner of the
combo box) to be able to see the preloaded list of items.

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
textbox1.Text=” “;
comboBox1.Text=”Chicken”;
//Add items to the combo box
comboBox1.Items.Add(“Chicken”);
comboBox1.Items.Add(“Beef”);
comboBox1.Items.Add(“Pork”);
comboBox1.Items.Add(“Vegetables”);
comboBox1.Items.Add(“Fish”);
comboBox1.Items.Add(“Squids”);
comboBox1.Items.Add(“Noodles”);
comboBox1.Items.Add(“Fruits”);

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
textBox1.Text=””;
textBox1.Text=Convert.ToString(comboBox1.SelectedItems);
}

Example 18:
Design and develop a simple program that demonstrates how to preload a
collection of items into the combo box. The program should be able to display one or
more selected items on a list box. When the user selects an item at the Combo box by
clicking it, this item will be displayed at the list box. The user must click the down arrow
to be able to see the preloaded list of items.

Coding Solutions:

private void Form1_Load(object sender, EventArgs e)


{
comboBox1.Text=”Banana Split”;
listBox1.Text=””;
comboBox1.Items.Add(“Banana Split”);
comboBox1.Items.Add(“Blueberry”);
comboBox1.Items.Add(“Cherry”);
comboBox1.Items.Add(“Mud Pie”);
comboBox1.Items.Add(“Nestle Crunch”);
comboBox1.Items.Add(“Oreo Cookies”);
comboBox1.Items.Add(“Choco Chip”);
comboBox1.Items.Add(“Chocolate Covered”);
comboBox1.Items.Add(“Rocky Road”);
comboBox1.Items.Add(“Strawberry”);
comboBox1.Items.Add(“Walnut Fudge”);
comboBox1.Items.Add(“Choco Almond”);
comboBox1.Items.Add(“Choco Mallows”);
comboBox1.Items.Add(“Brownies”);
comboBox1.Items.Add(“Butterfinger”);
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
listBox1.Items.Add(comboBox1.SelectedItem);
}

Example 19:

Design and develop a simple program that demonstrates how to preload a collection of
items into the combo box. The program should be able to display one or more selected
items on a list box with a confirmation using the button.

Coding Solution:

private void Form1_Load(object sender, EventArgs e)


{
comboBox1.Text=”Chicken”;
//Add items to the combo box
comboBox1.Items.Add(“Chicken”);
comboBox1.Items.Add(“Beef”);
comboBox1.Items.Add(“Pork”);
comboBox1.Items.Add(“Vegetables”);
comboBox1.Items.Add(“Fish”);
comboBox1.Items.Add(“Squids”);
comboBox1.Items.Add(“Noodles”);
comboBox1.Items.Add(“Fruits”);

private void button1_Click(object sender, EventArgs e)


{
listBox1.Items.Add(comboBox1.SelectedItem);
}

Lab. Ex.

1. Design and develop a simple application system that preloads a Combo box with
items. The user can select an item from the list to be displayed at the text box.
The user must click the down arrow to be able to see the list of preloaded items.
When the user selects an item at the Combo box by clicking it, this item will be
displayed at the text box.

Add the following items into the Combo box using the Items.Add method at the
Form_Load method:

Dilly Bar
Plain Dog
Cheese Dog
Chilimelt Dog
Relish Dog
Bacon n Cheese
Fudge Brownie
Banana Split
Peanut Buster

2. Design and develop a simple application system that preloads a Combo box with
items. The user can select an item from the List to be displayed at the list box.
The user must click the down arrow to be able to see the list of preloaded items.
When the user selects an item at the Combo box by clicking it, this item will be
displayed at the text box.

Add the following items into the Combo box using the Items.Add method at the
Form_Load method:

Al Tonno
Chorizo
Arrabiata
Pesto
Carbonara
Mushroom Sauce
Pasta
Mexicali
Veggies Heaven
Mushroom Galore
Neptune’s Fancy

3. Design and develop a simple application system that preloads a Combo box with
items. The user can select an item from the list to be displayed at the list box with
a confirmation using the button.

When the user selects an item at the Combo box and would like to order it, she
has to click the Order button to display the selected item into the list box.

Add the following Starbucks Café Menu into the Combo box using the Items.Add
method at the Form_Load method:

Cheese Tempura
Ceasar’s Salad
Cajun Burger
Citrus Pork
Burger Steak
Café Mocha
Café Latte
Cappuccino
Steamed Milk
Espresso
Brewed Coffee

You might also like