コード例 #1
0
        // Fyller listview för kvittots produkter med kvittots produkter.
        private void ListReceiptProducts()
        {
            ListViewItem selectedItem = null;

            try
            {
                selectedItem = ListViewReceipts.SelectedItems[0];
            }
            catch (ArgumentOutOfRangeException exc)
            {
                System.Diagnostics.Debug.WriteLine("Error when selecting receipt.");
                System.Diagnostics.Debug.WriteLine(exc.Message);
            }

            if (selectedItem != null)
            {
                string  receiptDate = selectedItem.SubItems[0].Text;
                Receipt receipt     = receiptController.GetByDate(receiptDate);
                selectedReceipt = receipt;

                ListViewReceiptProducts.Items.Clear();
                ListViewReceiptProducts.BeginUpdate();
                foreach (Product product in receipt.products)
                {
                    try
                    {
                        string[] productValues = new string[1];
                        productValues[0] = product.name;
                        ListViewItem item = new ListViewItem(productValues);
                        item.Tag = product.id;
                        ListViewReceiptProducts.Items.Add(item);
                    }
                    catch (Exception exc)
                    {
                        System.Diagnostics.Debug.WriteLine(exc.Message);
                    }
                }

                ListViewReceiptProducts.EndUpdate();
                ListViewReceiptProducts.Sort();
            }
        }