Object reference not set to an instance of an object

Posted by Ste on Stack Overflow See other posts from Stack Overflow or by Ste
Published on 2010-12-23T19:40:35Z Indexed on 2010/12/23 19:54 UTC
Read the original article Hit count: 154

Filed under:
|
|

I have this function that create runtime textbox:

int i = 0;
private TextBox[] addressBox = new TextBox[100];

private void appendNewTab()
{ 
    addressBox[i] = new TextBox();
    addressBox[i].KeyPress += 
        new KeyPressEventHandler(this.addressBox_KeyPress); 
    i++;
}

void addressBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
        MessageBox.Show(addressBox[i].Text);
    }
}

but i have Object reference not set to an instance of an object here

MessageBox.Show(addressBox[i].Text);

any suggestion?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET