title: How to return value of items in Listbox to Textbox
body: <p>my situation is that I need to add up all prices of items in a <code>Listbox</code> and have the total price in the textbox. I am using c# WinForms. This what I have so far but it is not working correctly by showing total, it is showing the price of the last item I press and not the total of all items</p>
  <pre><code>public class SelectedPizza
      {
          public string Size { get; set; }
          public string Name { get; set; }
          public string Price { get; set; }
  
          public string Format() =&gt; $&quot;{Size} {Name} {Price}&quot;; // Format inside Listbox
      }
      private void ButtonSizeClick(object sender, EventArgs e)
      {
          var button = (Button)sender;
          _selectedPizza.Size = button.Tag.ToString(); // Adds pizza size to order listbox
  
          if (_selectedPizza.Name != null)
              _selectedPizza.Price = GetPrice(_selectedPizza.Size);
      }
  
      private void ButtonNameClick(object sender, EventArgs e)
      {
          var button = (Button)sender;
          _selectedPizza.Name = button.Tag.ToString();
  
          if (_selectedPizza.Size != null)
              _selectedPizza.Price = GetPrice(_selectedPizza.Size);
  
          listBox1.Items.Add(_selectedPizza.Format()); // Adds pizza name to order listbox
      }
  private string GetPrice(string sSize)
          {
              string sPrice = &quot;0.00&quot;;
  
          if (sSize == &quot;Large&quot;)
              sPrice = &quot;11.90&quot;;
  
          TxtbxTotal.Text = sPrice;  // Displays price in order total textbox
          return sPrice;
      }
  </code></pre>