title: Sum of values of a listbox in wpf
body: <p>I have a <code>TextBox</code> in WPF and a <code>ListBox</code>. <code>ListBox</code> (listAmount) is containing some values and I want the sum of that values in that <code>TextBox</code> (txtTotalAmount).</p>
  
  <p>I am using currently this code:</p>
  
  <pre><code>int i = 0;
  int sum = 0;
  
  for (i = 0; i &lt; listAmount.Items.Count; i++)
  {
      sum = sum + Convert.ToInt32(listAmount.Items[i]);
  }
  
  txtTotalAmount.Text = sum.ToString();
  </code></pre>
  
  <p>And I get this error:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Windows.Controls.ListBoxItem' to
    type 'System.IConvertible'</p>
  </blockquote>
  
  <p>I will be greatfull to you.</p>