获取所选列表框项的对象信息 [英] Get object information of selected listbox item

查看:24
本文介绍了获取所选列表框项的对象信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的列表框中有对象,其中包含 BankAccount 类(余额、转账、提款方法)和 Wallet 类(姓名、生日等)的实例.)
我需要查看有关所选列表框对象 (lbAccounts) 的某些信息部分(如余额).

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).

列表框中的对象:

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;

希望能帮到你.

这篇关于获取所选列表框项的对象信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆