I have objects in my list box that contain an instance of the BankAccount
class (Balance, transfer, Withdraw methods) and Wallet
class (name, birthday, etc.)
I need to view certain parts of information (like balance) about the selected list box object (lbAccounts).
Objects in Listbox:
DateTime birth = Convert.ToDateTime("01/01/1970");
Wallet account = new Wallet("Bob", "Smith", birth);
BankAccount account1 = new BankAccount(account);
account1.DepositFunds(5000);
BankAccount account2 = new BankAccount(account);
account2.DepositFunds(300);
//Adding accounts to listbox
lbAccounts.Items.Add(account1);
lbAccounts.Items.Add(account2);
QUESTION: How do I get the balance of a selected listbox object?
You will get the object from selected item of list box.
BankAccount ba = lbAccounts.SelectedItem as BankAccount;
I hope it will help you.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments