Indexing 无法在两个文本框中显示帐户ID和余额
在列表框中选定的索引更改后,我似乎不知道如何在文本框中显示帐户ID和帐户余额。我有一个Customer类和一个Check account类(这是银行帐户类的一个子类)。代码中混乱的部分在底部 这是我的代码中有问题的部分:Indexing 无法在两个文本框中显示帐户ID和余额,indexing,outofrangeexception,bank,Indexing,Outofrangeexception,Bank,在列表框中选定的索引更改后,我似乎不知道如何在文本框中显示帐户ID和帐户余额。我有一个Customer类和一个Check account类(这是银行帐户类的一个子类)。代码中混乱的部分在底部 这是我的代码中有问题的部分: txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber(); txt
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
以下是代码的其余部分:
public partial class frmStart : Form
{
private static List<Customer_Account> customers;
private Customer_Account aCustomer;
private Saving_Account aSaver;
private static List<Saving_Account> savers;
private Checking_Account aChecker;
private static List<Checking_Account> checkers;
public frmStart()
{
InitializeComponent();
customers = new List<Customer_Account>();
checkers = new List<Checking_Account>();
savers = new List<Saving_Account>();
}
#region New form for Savings and Checking
private void lstFrmStartChecking_DoubleClick(object sender, EventArgs e)
{
//Shows Checking form
frmChecking showCheckingForm = new frmChecking();
this.Hide();
showCheckingForm.ShowDialog();
this.Close();
}
private void lstFrmStartSavings_SelectedIndexChanged(object sender, EventArgs e)
{
//Show Savings form
frmSavings showSavingForm = new frmSavings();
this.Hide();
showSavingForm.ShowDialog();
this.Close();
}
#endregion
#region Everything needed for TabPage1
//Sets CheckChanged event handler for either New customer or Existing Customer
private void rdoNewCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Visible = true;
groupBox3.Visible = false;
}
private void rdoExistingCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox3.Visible = true;
groupBox2.Visible = false;
}//End of CheckChanged event handler
//Button controls for Adding customer to our bank and Clearing the textboxes
//in the 1st group panel
private void btnAddCustomer_Click(object sender, EventArgs e)
{
AddCustomerAccountToList();
PopulateListBox(customers);
}
private void AddCustomerAccountToList()
{
double socialSecurity;
double phoneNumber;
double zipCode;
if (double.TryParse(txtTab1SocialSecurity.Text, out socialSecurity) && double.TryParse(txtTab1PhoneNumber.Text, out phoneNumber)
&& double.TryParse(txtTab1Zip.Text, out zipCode))
{
aCustomer = new Customer_Account(txtTab1SocialSecurity.Text, txtTab1Name.Text, txtTab1Address.Text, txtTab1City.Text,
txtTab1State.Text, txtTab1Zip.Text, txtTab1PhoneNumber.Text, txtTab1Email.Text);
customers.Add(aCustomer);
}
else
{
MessageBox.Show("Please be sure to use only numeric entries for: \nSocial Security \nPhone Number \nZip Code", "Non-numeric Entry");
}
}//End of AddCustomerAccount
private void btnTab1Clear_Click(object sender, EventArgs e)
{
foreach (Control ctrl in groupBox2.Controls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Clear();
}
txtTab1SocialSecurity.Focus();
}
}//end of button controls for 1st group panel
//Add CheckingAccount to List()
//Populate ListBox for List<>
private void PopulateListBox(List<Customer_Account> aListCustomerAccount)
{
lstTabPage1.Items.Clear();
lstTabPage2Checking.Items.Clear();
foreach (Customer_Account customer in aListCustomerAccount)
{
lstTabPage1.Items.Add(customer.GetCustomerName().ToUpper());
lstTabPage2Checking.Items.Add(customer.GetCustomerName().ToUpper());
}
}//End of Populate listbox
//Search for an existing member with name
private void txtTabPage1Search_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage1.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage1Search.Text))
{
lstTabPage1.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage1.Items[i]).StartsWith(txtTabPage1Search.Text.ToUpper()))
{
lstTabPage1.SetSelected(i, true);
}
else
{
lstTabPage1.SetSelected(i, false);
}
}
}//End of search
//This button will open a checking account for the customer
private void btnOpenCheckingAccount_Click(object sender, EventArgs e)
{
string acctID;
acctID = txtAccountID.Text;
aChecker = new Checking_Account(acctID, DateTime.Today, 0,
200, frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
//This button will open a saving account for the customer
private void btnOpenSavingsAccount_Click(object sender, EventArgs e)
{
aSaver = new Saving_Account(txtAccountID.Text, DateTime.Today, 0, 0.05,
frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
private static List<Customer_Account> GetCustomer()
{
return customers;
}
#endregion
#region Everything Needed for TabPage2
//Search TabPage 2 Checkers
private void txtTabPage2SearchChecking_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage2Checking.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage2SearchChecking.Text))
{
lstTabPage2Checking.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage2Checking.Items[i]).StartsWith(txtTabPage2SearchChecking.Text.ToUpper()))
{
lstTabPage2Checking.SetSelected(i, true);
}
else
{
lstTabPage2Checking.SetSelected(i, false);
}
}
}//End Search TabPage2 Checkers
//Display values in textboxes depending on user selection in listbox
private void lstTabPage2Checking_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
txtTab2SocialSecurity.Text = customers[lstTabPage2Checking.SelectedIndex].GetSocialSecurity().ToString();
txtTab2Name.Text = customers[lstTabPage2Checking.SelectedIndex].GetCustomerName().ToString();
txtTab2City.Text = customers[lstTabPage2Checking.SelectedIndex].GetCity().ToString();
txtTab2State.Text = customers[lstTabPage2Checking.SelectedIndex].GetState().ToString();
txtTab2Zip.Text = customers[lstTabPage2Checking.SelectedIndex].GetZip().ToString();
txtTab2PhoneNumber.Text = customers[lstTabPage2Checking.SelectedIndex].GetPhoneNumber().ToString();
txtTab2Email.Text = customers[lstTabPage2Checking.SelectedIndex].GetEmail().ToString();
txtTab2Address.Text = customers[lstTabPage2Checking.SelectedIndex].GetAddress().ToString();
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
}
public分部类frmStart:Form
{
私有静态列表客户;
私人客户账户;
私人储蓄账户;
私有静态列表保存器;
私人支票账户;
私有静态列表检查器;
公共frmStart()
{
初始化组件();
客户=新列表();
checkers=新列表();
savers=新列表();
}
#地区储蓄及支票新表格
私有void lstFrmStartChecking_双击(对象发送方,事件参数e)
{
//显示检查表
frmChecking showCheckingForm=新frmChecking();
this.Hide();
showCheckingForm.ShowDialog();
这个。关闭();
}
私有void lstfrmstartsaviations\u SelectedIndexChanged(对象发送方,事件参数e)
{
//出示存款单
frmSavings showSavingForm=新frmSavings();
this.Hide();
showSavingForm.ShowDialog();
这个。关闭();
}
#端区
#区域TabPage1所需的一切
//为新客户或现有客户设置CheckChanged事件处理程序
私有void rdoNewCustomer_CheckedChanged(对象发送方,事件参数e)
{
groupBox2.Visible=true;
groupBox3.Visible=false;
}
私有void rdoExistingCustomer_CheckedChanged(对象发送方,事件参数e)
{
groupBox3.Visible=true;
groupBox2.Visible=false;
}//CheckChanged事件处理程序的结束
//用于向银行添加客户和清除文本框的按钮控件
//在第一组小组中
私有无效btnAddCustomer_单击(对象发送者,事件参数e)
{
AddCustomerAccountToList();
公共信息发布箱(客户);
}
私有void AddCustomerAccountToList()
{
双重社会安全;
双电话号码;
双zipCode;
if(double.TryParse(txtab1socialsecurity.Text,out socialSecurity)和&double.TryParse(txtab1phonenumber.Text,out phoneNumber)
&&double.TryParse(txtTab1Zip.Text,out-zipCode))
{
aCustomer=新客户\ U账户(txtab1socialsecurity.Text、txtab1name.Text、txtab1address.Text、txtab1city.Text、,
txttab 1state.Text、txttab 1zip.Text、txttab 1phonenumber.Text、txttab 1mail.Text);
添加(aCustomer);
}
其他的
{
MessageBox.Show(“请确保只使用数字输入:\n社会安全\n电话号码\n IP代码”,“非数字输入”);
}
}//AddCustomerAccount结束
私有无效BTNTAB1清除\u单击(对象发送者,事件参数e)
{
foreach(groupBox2.Controls中的控件ctrl)
{
如果(ctrl为文本框)
{
((文本框)ctrl).Clear();
}
txtTab1SocialSecurity.Focus();
}
}//第一组面板的按钮控制结束
//将CheckingAccount添加到列表()中
//为列表填充列表框
私有void PopulateListBox(列表aListCustomerAccount)
{
lstabpage1.Items.Clear();
lstabpage2检查.Items.Clear();
foreach(客户\ aListCustomerAccount中的客户帐户)
{
lstabpage1.Items.Add(customer.GetCustomerName().ToUpper());
lstabpage2检查.Items.Add(customer.GetCustomerName().ToUpper());
}
}//填充列表框的结尾
//搜索名为的现有成员
私有void txttabage1search_TextChanged(对象发送方,事件参数e)
{
对于(int i=0;itxtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber().ToString();