c# - 将控制器类中的列表添加到表单列表框
问题描述
嗨,我有一个问题,我目前遇到了问题。我试图让 myA 列表显示在我的管理帐户的列表框中,但是当我运行程序时,列表框中没有显示任何内容。
这是我的控制器类,它包含 MakeAccounts() 和 AddAccounts() 的方法
// Methods for handling accounts
public void MakeAccounts()
{
myA.Add(new Account.Everyday());
myA.Add(new Account.Investment(5, 10));
myA.Add(new Account.Omni(5, 10, -100));
myA[0].Balance = 50;
myA[1].Balance = 500;
myA[2].Balance = 5000;
// WriteBinaryData();
}
这是我的 Manage Accounts From 类,它有一个 DisplayAccounts() 方法,我在 Initialize Component 部分中调用了该方法。
private void DisplayAccounts()
{
listBoxManageAccounts.Items.Clear();
foreach (Account account in control.myA)
{
listBoxManageAccounts.Items.Add(account);
}
if (listBoxManageAccounts.Items.Count >= 1)
{
listBoxManageAccounts.SelectedIndex = 0;
}
}
这是我的帐户类:
public class Account
{
static int nextAccountID = 1;
protected int accountID;
protected string typeName;
protected decimal balance;
protected string lastTransaction;
public Account()
{
accountID = nextAccountID;
nextAccountID++;
balance = 0;
lastTransaction = "There are no transactions.";
}
public decimal Balance
{
get { return balance; }
set { balance = value; }
}
// public int Interest
// {
// set { Interest = 4; }
// }
public class Everyday : Account
{
public Everyday()
{
typeName = "Everyday";
}
}
public class Investment : Account
{
protected decimal interestRate;
protected decimal failedTransFee;
public Investment(decimal newInterestRate, decimal newFailedTransFee)
{
typeName = "Investment";
interestRate = newInterestRate;
failedTransFee = newFailedTransFee;
}
}
public class Omni : Account
{
protected decimal interestRate;
protected decimal failedTransFee;
protected decimal overdraftLimit;
public Omni(decimal newInterestRate, decimal newFailedTransFee, decimal newOverdraftLimit)
{
typeName = "Omni";
interestRate = newInterestRate;
failedTransFee = newFailedTransFee;
overdraftLimit = newOverdraftLimit;
}
}
}
所以我想要发生的是,当打开此表单时,我希望账户(日常、投资、全方位)立即出现在列表框中。目前,当我打开此表单时,没有任何反应。谁能告诉我发生了什么或我哪里出错了?
解决方案
推荐阅读
- selenium - Selenium Webdriver-如何单击网页中的“登录”按钮
- java - java - 使用 IgniteFuture 进行单元测试
- javascript - 来自 localStorage url 的图像返回 [object ArrayBuffer]
- php - 对日期时间字段运行选择查询时出错
- angularjs - 我需要在单击按钮时调用 AngularJS 中组件的 HTML 中定义的脚本中的函数。我怎样才能做到这一点?
- android - 从服务上下文中使用 fileProvider
- delphi - DKLang 的 StoreList 和 Virtual treeview 的标题文本翻译
- google-bigquery - 元数据库中的大查询超时
- r - 英特尔 MKL/至强融核卸载运行时问题 - 自动卸载不起作用
- wpf - 许多意外的“无法使用绑定检索值”错误