private void constructCoinBoxDisplay(ListView CoinBoxDisplay, CoinBox CoinBoxToDisplay) { CoinBoxDisplay.Items.Clear(); List<Coin.Denomination> reverseCoinList = new List<Coin.Denomination>(Coin.AllDenominations); reverseCoinList.Reverse(); foreach (Coin.Denomination coinDenomination in reverseCoinList) { int coinCount = CoinBoxToDisplay.coinCount(coinDenomination); decimal coinsValue = coinCount * Coin.ValueOfCoin(coinDenomination); ListViewItem coinRow = new ListViewItem(coinDenomination.ToString()); coinRow.SubItems.Add(coinCount.ToString()); coinRow.SubItems.Add(string.Format("{0:c}", coinsValue)); CoinBoxDisplay.Items.Add(coinRow); } ListViewItem totalRow = new ListViewItem("Total"); totalRow.SubItems.Add(string.Empty); totalRow.SubItems.Add(string.Format("{0:c}", CoinBoxToDisplay.ValueOf)); CoinBoxDisplay.Items.Add(totalRow); }
/// <summary> /// update the values in a coin box listView display /// </summary> /// <param name="listViewCoinBox">the ListView to update</param> /// <param name="_coinBox">the CoinBox from which to obtain the data</param> private void updateCoinBoxDisplayData(ListView listViewCoinBox, CoinBox _coinBox) { int i = 0; int coinCount = 0; foreach (Coin.Denomination cn in Coin.AllDenominations) { //listViewCoinBox.Items.Find() //listViewCoinBox.FindItemWithText(cn.ToString()) listViewCoinBox.Items[i].SubItems[1].Text = _coinBox.coinCount(cn).ToString(); coinCount += _coinBox.coinCount(cn); listViewCoinBox.Items[i].SubItems[2].Text = string.Format("{0:C}",_coinBox.coinCount(cn) * Coin.ValueOfCoin(cn)); i++; } listViewCoinBox.Items[i].SubItems[1].Text = coinCount.ToString(); listViewCoinBox.Items[i].SubItems[2].Text = string.Format("{0:C}", _coinBox.ValueOf); }