예제 #1
0
        private void UpdateListView(Products product, ListViewAction action, int index)
        {
            ListViewItem item = new ListViewItem(product.ItemNumber.ToString());

            item.SubItems.Add(product.ProductName);
            item.SubItems.Add(product.Categories.CategoryName);

            // Use InvariantCulture to format the decimal with dot instead of comma.
            item.SubItems.Add(product.SalePrice.ToString("0.00",
                                                         System.Globalization.CultureInfo.InvariantCulture));
            item.SubItems.Add(product.DeliveryPrice.ToString("0.00",
                                                             System.Globalization.CultureInfo.InvariantCulture));

            item.SubItems.Add(product.Amount.ToString());
            item.Tag = product;

            if (action == ListViewAction.Add)
            {
                lvProducts.Items.Add(item);
            }

            if (action == ListViewAction.Update && index > Constant.IndexNone)
            {
                lvProducts.Items[index] = item;
            }
        }
예제 #2
0
        private void AddAction(string methodName, double x, double y)
        {
            var action = new ListViewAction
            {
                MouseAction = methodName,
                Description = "Values: x = " + x.ToString() + " and y = " + y.ToString()
            };

            Actions.Add(action);
        }
예제 #3
0
        private void UpdateListView(Partners partner, ListViewAction action, int index)
        {
            ListViewItem item = new ListViewItem(partner.CompanyName);

            item.SubItems.Add(partner.OwnerName);
            item.SubItems.Add(partner.CityName);
            item.SubItems.Add(partner.CompanyNumber);
            item.Tag = partner;

            if (action == ListViewAction.Add)
            {
                lvPartners.Items.Add(item);
            }

            if (action == ListViewAction.Update && index > Constant.IndexNone)
            {
                lvPartners.Items[index] = item;
            }
        }
예제 #4
0
        private void UpdateListView(DeliveryItems deliveryItem, ListViewAction action, int index)
        {
            ListViewItem item = new ListViewItem(deliveryItem.Products.ProductName);

            // Use InvariantCulture to format the decimal with dot instead of comma.
            item.SubItems.Add(deliveryItem.DeliveryPrice.ToString("0.00",
                                                                  System.Globalization.CultureInfo.InvariantCulture));

            item.SubItems.Add(deliveryItem.Amount.ToString());
            item.Tag = deliveryItem;

            if (action == ListViewAction.Add)
            {
                lvDeliveryItems.Items.Add(item);
            }

            if (action == ListViewAction.Update && index > Constant.IndexNone)
            {
                lvDeliveryItems.Items[index] = item;
            }
        }
예제 #5
0
        private void UpdateListView(Deliveries delivery, ListViewAction action, int index)
        {
            ListViewItem item = new ListViewItem(delivery.DeliveryDate.ToShortDateString());

            item.SubItems.Add(delivery.Partners.CompanyName);
            item.SubItems.Add(delivery.DocumentNumber.ToString());

            // Use InvariantCulture to format the decimal with dot instead of comma.
            item.SubItems.Add(delivery.DeliveryPrice.ToString("0.00",
                                                              System.Globalization.CultureInfo.InvariantCulture));

            item.Tag = delivery;

            if (action == ListViewAction.Add)
            {
                lvDeliveries.Items.Add(item);
            }

            if (action == ListViewAction.Update && index > Constant.IndexNone)
            {
                lvDeliveries.Items[index] = item;
            }
        }
		/// <summary>
		/// Applies the given state to the given item.
		/// Raises events, too.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="action">The action.</param>
		/// <param name="stateImageIndex">Index of the state image.</param>
		/// <param name="raiseEvents">if set to <c>true</c> [raise events].</param>
		private void SetTriStateToItem(
			ListViewItem item,
			ListViewAction action,
			int stateImageIndex,
			bool raiseEvents )
		{
			bool canSet = true;

			if ( raiseEvents )
			{
				ItemCheckEventArgs args =
					new ItemCheckEventArgs(
					item.Index,
					ConvertStateImageIndexToCheckState(
					stateImageIndex ),
					ConvertStateImageIndexToCheckState(
					item.StateImageIndex ) );

				OnItemCheck( args );

				ItemCheckTriStateEventArgs triArgs =
					new ItemCheckTriStateEventArgs(
					item,
					action,
					ConvertStateImageIndexToCheckState(
					stateImageIndex ),
					ConvertStateImageIndexToCheckState(
					item.StateImageIndex ) );

				OnItemCheckTriState( triArgs );

				canSet = !triArgs.Cancel;
			}

			if ( canSet )
			{
				// Actually set.
				// THIS IS THE ONLY PLACE to set.
				item.StateImageIndex = stateImageIndex;

				if ( raiseEvents )
				{
					ItemCheckedEventArgs args =
						new ItemCheckedEventArgs( item );

					OnItemChecked( args );

					ItemCheckedTriStateEventArgs triArgs =
						new ItemCheckedTriStateEventArgs(
						item,
						action,
						item.StateImageIndex );

					OnItemCheckedTriState( triArgs );
				}
			}
		}
		/// <summary>
		/// Toggles the tri state check.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="action">The action.</param>
		private void ToggleTriStateCheck(
			ListViewItem item,
			ListViewAction action )
		{
			if ( item.StateImageIndex == TriStateUncheckedStateImageIndex )
			{
				SetTriStateToItem(
					item,
					action,
					TriStateCheckedStateImageIndex,
					true );
			}
			else
			{
				SetTriStateToItem(
					item,
					action,
					TriStateUncheckedStateImageIndex,
					true );
			}
		}
		/// <summary>
		/// Applies a new check state to the given list view item.
		/// The UseTriStateCheckBoxes property must be set to TRUE.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="action">The action.</param>
		/// <param name="checkState">State of the check.</param>
		private void DoSetItemCheckState(
			ListViewItem item,
			ListViewAction action,
			CheckState checkState )
		{
			// Use ListViewAction.ByKeyboard here, 
			// to indicate that it was called from outside.
			SetTriStateToItem(
				item,
				action,
				ConvertCheckStateToImageIndex( checkState ),
				true );
		}
			/// <summary>
			/// Initializes a new instance of the <see cref="ItemCheckedTriStateEventArgs"/> class.
			/// </summary>
			/// <param name="item">The item.</param>
			/// <param name="action">The action.</param>
			/// <param name="stateImageIndex">Index of the state image.</param>
			public ItemCheckedTriStateEventArgs(
				ListViewItem item,
				ListViewAction action,
				int stateImageIndex )
				:
				base( item )
			{
				this.action = action;
				this.stateImageIndex = stateImageIndex;
			}
			/// <summary>
			/// Constructor.
			/// </summary>
			/// <param name="item">The item.</param>
			/// <param name="action">The action.</param>
			/// <param name="newCheckValue">The new check value.</param>
			/// <param name="currentCheckValue">The current check value.</param>
			public ItemCheckTriStateEventArgs(
				ListViewItem item,
				ListViewAction action,
				CheckState newCheckValue,
				CheckState currentCheckValue )
				:
				base( item.Index, newCheckValue, currentCheckValue )
			{
				this.item = item;
				this.action = action;
			}