This application is used by a company that sells musical
instruments of various kinds. During order processing, a customer would specify
the items he or she wants and a clerk would find them. In other cases, a
customer may want to describe the type of item that he or she wants. The type
can be as precise as a guitar, a microphone, or a piano. In other cases, the
customer may have an idea of the desired item but cannot make up his or her
mind. For example, a customer may want to buy a piano but think that later on,
he or she may need electronic sounds. A customer may also want to purchase a
drum, but there are various kinds: classic, electronic, or drum machine.

Over all, a clerk would assist a customer locate an item most appropriately
suiting to the customer's needs. This application includes a process, through
some combo boxes, that allows an employee to locate an item.

Practical
Learning: Starting a Custom Collection Class

Start Microsoft Visual C# and create a new Windows Application named MusicalInstrumentStore2

To create a dialog box, on the main menu, click Project -> Add Windows
Form...

Set the name to CategoryEditor and click Add

Design the form as follows:

Control

Text

Name

Other Properties

Label

&Category:

TextBox

txtCategory

Modifiers: Public

Button

OK

btnOK

DialogResult: OK

Button

Cancel

btnCancel

DialogResult: Cancel

Form Property

Value

FormBorderStyle

FixedDialog

Text

Category Editor

StartPosition

CenterScreen

AcceptButton

btnOK

CancelButton

btnCancel

MaximizeBox

False

MinimizeBox

False

ShowInTaskbar

False

To create a dialog box, on the main menu, click Project -> Add Windows
Form...

private void btnNewCategory_Click(object sender, EventArgs e)
{
CategoryEditor editor = new CategoryEditor();
if (editor.ShowDialog() == DialogResult.OK)
{
if (editor.txtCategory.Text.Length > 0)
{
string strNewCategory = editor.txtCategory.Text;
// Make sure the category is not yet in the list
if (cbxCategories.Items.Contains(strNewCategory))
MessageBox.Show(strNewCategory + " is already in the list");
else
{
// Since this is a new category, add it to the combox box
cbxCategories.Items.Add(strNewCategory);
// Just in case the user wanted to use this new category
// select it
cbxCategories.Text = strNewCategory;
}
}
}
}

Return to the Item Editor dialog box and double-click the New Item Type
button

// This method is used to add a new item to the collection
public virtual int Add(object value)
{
// Find out if the array is getting too small for the next item(s)
// If it is, increase its size by 5
if (Count == items.Length)
Array.Resize(ref items, items.Length + 5);
if (counter < items.Length)
{
items[counter] = value;
counter++;
return counter - 1;
}
else
return -1;
}

In the Class View, double-click ItemEditor

In the top section of the file, add the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

In the Solution Explorer, double-click ItemEditor.cs

On the form, double-click the Create button and implement its event
as follows: