Example #1
0
 private void DeleteOrderItem()
 {
     int controlCount;
     int currentControlIndex;
     int count;
     OrderItemControl tempProductOrder;
     //when deleting OrderItemControls you must reorder and redraw the existing ones
     controlCount = ProductOrderPanel.Controls.Count;
     currentControlIndex = ProductOrderPanel.Controls.IndexOf(ProductContextMenu.SourceControl);
     //if the control is not the last one and you need to reorder and redraw the existing ones
     //that are below it
     if (currentControlIndex + 1 < controlCount)
     {
         for(count = (currentControlIndex + 1);count < controlCount;count++)
         {
             tempProductOrder = ProductOrderPanel.Controls[count] as OrderItemControl;
             tempProductOrder.Location = new System.Drawing.Point(0, tempProductOrder.Location.Y - 24);
         }
         ProductOrderPanel.Controls.Remove(ProductContextMenu.SourceControl);
         //if it is the last control you can just delete it without any reordering logic
     }
     else
     {
         ProductOrderPanel.Controls.Remove(ProductContextMenu.SourceControl);
     }
     //decrement yPositionOrderItemControl so the next control drawn is placed in the correct
     //location
     yPositionOrderItemControl = yPositionOrderItemControl - 24;
 }
Example #2
0
        private void CreateNewRow(object sender, System.EventArgs e)
        {
            //Handles NewOrderItemButton.Click

            if(!SaveOrderButton.Enabled)
                SaveOrderButton.Enabled = true;
            tempProductOrder = new PurchaseOrder.OrderItemControl();

            tempProductOrder.Location = new System.Drawing.Point(0, yPositionOrderItemControl);
            tempProductOrder.Size = new System.Drawing.Size(608, 24);

            //set the ContextMenu of the OrderItem control to productContextMenu
            tempProductOrder.ContextMenu = this.ProductContextMenu;
            //by default, the TexBox control uses a default ContextMenu that
            //provides Undo, Cut, Copy, Paste, and Select All operations. The
            //ProductOrder control exposes the ContextMenu property of the
            //DiscountTextBox and QuantityTextBox with the QuantityTextBox_ContextMenu
            //and the DiscountTextBoxC_ontextMenu properties
            tempProductOrder.DiscountTextBox_ContextMenu = this.ProductContextMenu;
            tempProductOrder.QuantityTextBox_ContextMenu = this.ProductContextMenu;
            //set the default values of the order
            tempProductOrder.OrderQuantity = 1;
            tempProductOrder.OrderDiscount = "0.00%";
            //call the GetProductData method to populate the OrderItemControl
            tempProductOrder.GetProductData(MainModule.northwindData.Tables["Products"]);

            ProductOrderPanel.Controls.Add(tempProductOrder);
            //increment yPosOrderItemControl so the next control drawn appears below the current one
            yPositionOrderItemControl = yPositionOrderItemControl + 24;
        }