2012-04-19 2 views
0

Я пишу программу с двумя вкладками. На первой вкладке пользователь вводит информацию об учетной записи Клиента. На второй вкладке есть поле со списком, которое содержит имя учетной записи, и при выборе той же информации, введенной на первой сохраненной вкладке, необходимо заполнить текстовые поля той же информацией на второй вкладке. Я сделал это раньше, и я использую ту же структуру, но она не работает. Я также собираю эту информацию из связанного класса, но все выглядит правильно. Может кто-нибудь сказать мне, что не так.Заполнение текстового поля из выбора combobox

public partial class Form1 : Form 
{ 
    ArrayList account; 

    public Form1() 
    { 
     InitializeComponent(); 
     account = new ArrayList(); 
    } 

    //here we set up our add customer button from the first tab 
    //when the information is filled in and the button is clicked 
    //the name on the account will be put in the combobox on the second tab 
    private void btnAddCustomer_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      CustomerAccount aCustomerAccount = new CustomerAccount(txtAccountNumber.Text, txtCustomerName.Text, 
      txtCustomerAddress.Text, txtPhoneNumber.Text); 
      account.Add(aCustomerAccount); 

      cboClients.Items.Add(aCustomerAccount.GetCustomerName()); 
      ClearText(); 
     } 
     catch (Exception) 
     { 
      MessageBox.Show("Make sure every text box is filled in!", "Error", MessageBoxButtons.OK); 
     } 
    } 


    private void ClearText() 
    { 
     txtAccountNumber.Clear(); 
     txtCustomerName.Clear(); 
     txtCustomerAddress.Clear(); 
     txtPhoneNumber.Clear(); 
    } 

Это то место, где я столкнулся с проблемой. Он говорит, что нет никакого определения для «ACCOUNTNUMBER» или любой из других

private void cboClients_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     txtAccountNumberTab2.Text = account[cboClients.SelectedIndex].accountNumber 
     txtCustomerNameTab2.Text = account[cboClients.SelectedIndex].customerName; 
     txtCustomerAddressTab2.Text=account[cboClients.SelectedIndex].customerAddress; 
     txtCustomerPhoneNumberTab2.Text=account[cboClients.SelectedIndex].customerPhoneNo; 
    } 
+0

'account' относится к' arraylist' , Похоже, что тебе не хватает роли. Или еще лучше, измените свой 'arraylist' на' List '. –

+0

Если вы не ограничены своей версией .Net, посмотрите на замену ArrayList более современной коллекцией. Вот хороший читать http://en.csharp-online.net/CSharp_Generics_Recipes%E2%80%94Replacing_the_ArrayList_with_Its_Generic_Counterpart –

ответ

2

ArrayList содержит объекты, Вы должны бросить его УЧЁТНАЯЗАПИСЬ

private void cboClients_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    CustomerAccount custAccount = account[cboClients.SelectedIndex] as CustomerAccount; 
    if(custAccount != null) 
    { 
     txtAccountNumberTab2.Text = custAccount.accountNumber 
     txtCustomerNameTab2.Text = custAccount.customerName; 
     txtCustomerAddressTab2.Text=custAccount.customerAddress; 
     txtCustomerPhoneNumberTab2.Text=custAccount.customerPhoneNo; 
    } 
} 
+0

Большое вам спасибо! –

Смежные вопросы