In this exercise, you’ll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators.

In this exercise, you’ll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators. Then, you’ll modify the code for the Inventory Maintenance form so it uses these features. Getting Started • Download the HW3Start project from Canvas. Unzip the compressed folder and place it in your class folder on your jump drive. • Open up the HW3Start solution. At the top of the code, include a comment with your name and class. For example, the comment I would enter for my assignment would be // Sherry Albright – CIT1755. • Review the code for the InvItemList class so you understand how it works. Then, review the code for the Inventory Maintenance form to see how it uses this class. Finally, run the application to see how it works. Add an index to the InvItemList class • Delete the GetItemByIndex method from the InvItemList class, and replace it with an indexer that receives an int value. This indexer should include both get and set accessors, and the get accessor should check that the value that’s passed to it is a valid index. If the index isn’t valid, the accessor should throw an ArgumentOutOfRangeException with a message that consists of the index value. • Modify the Invoice Maintenance form to use this indexer instead of the GetItemByIndex method. Then, test the application to be sure it still works. Add overloaded operators to the InvItemList class • Add overloaded + and – operators to the InvItemList class that add and remove an inventory item from the inventory item list. • Modify the Inventory Maintenance form to use these operators instead of the Add and Remove methods. Then, test the application to be sure it still works. Add a delegate and an event to the InvItemList class • Add a delegate named ChangeHandler to the InvItemList class. This delegate should specify a method with a void return type and an InvItemList parameter. • Add an event named Changed to the InvItemList class. This event should use the ChangeHandler delegate and should be raised any time the inventory item list changes. • Modify the Inventory Maintenance form to use the Changed event to save the inventory items and refresh the list box any time the list changes. To do that, you’ll need to code an event handler that has the signature specified by the delegate, you’ll need to wire the event to the event handler, and you’ll need to remove any unnecessary code from the event handlers for the Save and Delete buttons. When you’re done, test the application to be sure it still works.

Mine works but it only populates zero’s in the list box.

Haven’t Found The Relevant Content? Hire a Subject Expert to Help You With
In this exercise, you’ll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators.
Post Your Own Question And Get A Custom Answer
Hire Writer

Heres my code so far:

frmInvMaint.cs:

namespace InventoryMaintenance

{

   public partial class frmInvMaint : Form

   {

       private InvItemList invItems = new InvItemList();

       public frmInvMaint()

      {

         InitializeComponent();

           // register event handler (connect the event to the Invoiceupdated method)

           invItems.Changed += new InvItemList.InvItemListChanged(ItemUpdated);

       }

       private void ItemUpdated(InvItem ChangedInvItem, string OperationMessage)

       {

           MessageBox.Show(ChangedInvItem.GetDisplayText() +”n” + OperationMessage + “nCurrent Inventory Item count: ” + invItems.Count);

       }

       //event handler for the add button

       private void ChangedInvItem_TextChanged(object sender, System.EventArgs e)

       {

       }

       //event handler for the clear button

       private void ClearInvItem(object sender, System.EventArgs e)

       {

       }

       private void FillItemListBox()

      {

           InvItem item = new InvItem();

         lstItems.Items.Clear();

           for (int i = 0; i < invItems.Count; i++)

           {

               lstItems.Items.Add(item.GetDisplayText());

           }

      }

       private void frmInvMaint_Load(object sender, System.EventArgs e)

      {

         invItems.Fill();

      }

       private void btnAdd_Click(object sender, System.EventArgs e)

      {

           frmNewItem newItemForm = new frmNewItem();

           InvItem invItem = newItemForm.GetNewItem();

           if (invItem != null)

           {

               invItems.Add(invItem);

               invItems.Save();

               FillItemListBox();

           }

           {

               this.lstItems.TextChanged +=

           new System.EventHandler(this.ChangedInvItem_TextChanged);

           }

       }

       private void btnDelete_Click(object sender, System.EventArgs e)

       {

           this.lstItems.TextChanged +=

               new System.EventHandler(this.ClearInvItem);

           InvItem invItem = new InvItem();

           int i = lstItems.SelectedIndex;

           if (i != -1)

           {

               string message = “Are you sure you want to delete “

                   + invItem.Description + “?”;

               DialogResult button =

                   MessageBox.Show(message, “Confirm Delete”,

                   MessageBoxButtons.YesNo);

               if (button == DialogResult.Yes)

               {

                   invItems.Remove(invItem);

                   invItems.Save();

                   FillItemListBox();

               }

           }

       }

      private void btnExit_Click(object sender, EventArgs e)

      {

         this.Close();

      }

   }

}

InvItemList.cs:

namespace InventoryMaintenance

{

   public class InvItemList

   {

       private List<InvItem> invItems;

       // delegate for event

       public delegate void InvItemListChanged

       (InvItem ChangedInvItem, string OperationMessage);

       // event declaration tied to inventotyitemListChanged

       public event

       InvItemListChanged Changed;

       //default constructor

       public InvItemList()

       {

           invItems = new List<InvItem>();

       }

       public int Count

       {

           get

           {

               return invItems.Count;

           }

       }

       public object InvItemList1 { get; internal set; }

       // indexer (gets a inventory item by position (index) in the list)

       public InvItem this[int index]

       {

           get

           {

               if

               (index < 0)

               {

                   // lowest index value for an item in the list is 0

                   throw new

                   ArgumentOutOfRangeException(index.ToString());

               }

               else if

               (index >= invItems.Count)

               {

                   // list is 0 based. If the Count is 3, the first item in the list is at index 0

                   // and the last item in the list is at index 2

                   throw new ArgumentOutOfRangeException(index.ToString());

               }

               return

               invItems[index];

           }

           set

           {

               invItems[index] = value

               ;

               Changed(invItems[index],

               “Inventory Items information was updated!”

               );

           }

       }

       // Add method to add invitems to the list

       public void Add(InvItem InvItemIn)

       {

           invItems.Add(InvItemIn);

           // fire change event

           Changed(InvItemIn, “Inventory Item information was added to the list!”);

       }

       // Remove method to delete studentgrade from the list

       public

       void

       Remove(InvItem InvItemIn)

       {

           invItems.Remove(InvItemIn);

           // fire change event

           Changed(InvItemIn, “Inventory Item information was removed from the list!”);

       }

       // operators for + and –

       public static InvItemList operator +(InvItemList invItem, InvItem item)

       {

           invItem.Add(item);

           return

           invItem;

       }

       public static InvItemList operator -(InvItemList invItem, InvItem item)

       {

           invItem.Remove(item);

           return

          invItem;

       }

       public void Add(int itemNo, string description, decimal price)

       {

           InvItem i = new InvItem(itemNo, description, price);

           invItems.Add(i);

       }

       public void Fill()

       {

           invItems = InvItemDB.GetItems();

       }

       public void Save()

       {

           InvItemDB.SaveItems(invItems);

       }

   }

}

superadmin (28431)
New York University
15 MILLION STUDENTS HELPED!

Hire an Expert to Help you

Hire Verified Expert

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
Have a homework question? Get help from verified tutors now!

Are You Looking For Assignment Help? We Can Certainly Assist You

Sometimes it is hard to do all the work on your own

Let us help you get a good grade on your paper. Get professional help and free up your time for more important courses. Let us handle your;

  • ~Dissertations
  • ~Essays
  • ~All Assignments

  • ~Research papers
  • ~Term papers