i've only been programming for a few weeks now and this is also my first time posting on this forum so i will try and get everything formatted correctly with the code and what not.
first of all im using visual studio 2008, programing in c#, and making a wpf application.
what im trying to make is a program that i can use for balancing my checkbook. to give an idea of how it works, it has two radio buttons, one for writing checks and one for making deposits. then it has 5 text boxes that you input the date, amount, who its to, exct. after you click the add button it adds that data plus the balance to a listview. (this part of my program works correctly)
this is the code that i have used to do this.
(i found this way of adding things to a listview on the internet and it was the only way i was able to do it, if this is the main source of my problem please let me know. i thoutht an array would be better but i havent figured out how to add an array correctly.)
<ListView Margin="17,84,14,89" Name="ledgerView">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding LedgerDate}" Width="120"/>
<GridViewColumn Header="Check Number" DisplayMemberBinding="{Binding LedgerCheckNumber}" Width="132"/>
<GridViewColumn Header="Transaction Type" DisplayMemberBinding="{Binding LedgerTransactionType}" Width="120"/>
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding LedgerDescription}" Width="280"/>
<GridViewColumn Header="Amount" DisplayMemberBinding="{Binding LedgerAmount}" Width="120"/>
<GridViewColumn Header="Balance" DisplayMemberBinding="{Binding LedgerBalance}" Width="120"/>
</GridView>
</ListView.View>
</ListView>
that is the xaml code for the listview and here is the actual code that takes place when you click the add transaction button.
public void AddTransaction()
{
try
{
string date = dateBox.Text;
string checkNumber = checkNoBox.Text;
string description = descriptionBox.Text;
double amount = double.Parse(amountBox.Text);
string transactionType;
double currentBalance = double.Parse(balanceBox.Text);
if (writingRadio.IsChecked.HasValue && writingRadio.IsChecked.Value)
{
transactionType = "Withdrawal";
amount = 0 - amount;
}
else
{
transactionType = "Deposit";
amount = 0 + amount;
}
double newBalance = currentBalance + amount;
balanceBox.Text = newBalance.ToString("0,0.00");
ledgerView.Items.Add(new Transaction()
{
LedgerDate = date,
LedgerCheckNumber = checkNumber,
LedgerTransactionType = transactionType,
LedgerDescription = description,
LedgerAmount = amount.ToString("0,0.00"),
LedgerBalance = newBalance.ToString("0,0.00")
});
ClearInput();
}
catch (FormatException)
{
MessageBox.Show("Amount value must be numbers only " + amountBox.Text + " will not work");
}
}
here is the Transaction class that is used.
public class Transaction
{
public string LedgerDate { get; set; }
public string LedgerCheckNumber { get; set; }
public string LedgerTransactionType { get; set; }
public string LedgerDescription { get; set; }
public string LedgerAmount { get; set; }
public string LedgerBalance { get; set; }
*edit: It is a forward slash to end the code tags, not a backslash. Thanks for using them.
now as i said all that works fine it adds all the correct information to the listview.
the problem comes when i want to delete a transaction. i use this code to perform the actual removal of the entire row from the listview.
ledgerView.Items.RemoveAt(0);
that also works fine but the problem i need help with is that before using that code, i need to some how get the value of the amount that is being deleted and use that to recalculate the balance. i havent been able to find any way of doing that and i have tried figuring it out on my own to no avail.
thanks in advance for any help you can give me. sorry the post is so long and if my code is sloppy.
This post has been edited by Martyr2: 15 April 2008 - 11:02 AM

New Topic/Question
Reply




MultiQuote








|