I'm working on this application that gets user's input and puts them into a ListBox and also finds the sum of those numbers(everything works fine). My issue is that every time the user enters a new number that number is being shown in the window(and I don't want that), instead I only want the current sum of all the ListBox numbers to be shown on the window.So if the users enter a new number a new sum should be shown on the window. Please help me. Thank you so much in advanced. Here's my code that runs just fine....
private void ClickToAddMoreCoins(object sender, RoutedEventArgs e)
{
int sum = 0;
//Hides InputBox and takes input text from user.
InputBox.Visibility = System.Windows.Visibility.Collapsed;
// Ensuring that input from user is a integer number
String input = InputTextBox.Text;
int result = 0;
if (int.TryParse(input, out result))
{
//Adding number of coins to CoinListBox
CoinListBox.Items.Add(result);
}
else
{
MessageBox.Show("Please enter a number of coins");
}
sum = CoinListBox.Items.Cast<object>().Sum(x => Convert.ToInt32(x));
if(sum > 30)
{
//Removing last coin in case number of coins exceeds 30
CoinListBox.Items.RemoveAt(CoinListBox.Items.Count - 1);
MessageBoxResult answer = MessageBox.Show("You cannot enter more than 30 coins. Do you want to end?", "Message", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (answer == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
}
}
// Resets InputBox.
InputTextBox.Text = String.Empty;
}