Object reference not set to an instance of an object
- by Ste
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?