Reputation: 41
orderNo
is increased by 1 everytime the createOrder form is opened. The orderNo
is not displaying in the textbox11
. I have to enter something into the textbox for it to change automatically to the counter.
public int orderNo;
private void textBox11_TextChanged(object sender, EventArgs e)
{
textBox11.Text = Convert.ToString(orderNo);
}
EDIT - put code into form_load
, but the counter seems not to change once createOrder
form is opened.
Upvotes: 0
Views: 3583
Reputation: 14389
Josh is correct if you want to make the functionality you wish on Load_Form event
add:
textBox11.Text = Convert.ToString(orderNo);
or add a second textbox
and set:
textBox2.Text=orderNo.ToString();
textBox2.Visible=False;
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox11.Text = Convert.ToString(orderNo);
}
Upvotes: 0
Reputation: 4860
The reason is that textBox_TextChanged
is not going to be called by the text box until user (or other piece of code) changes it's contents. Wherever you set orderNo
should update the text. Do something like the following
private int orderNo;
public int OrderNo
{
get { return this.orderNo; }
set { this.orderNo = value; textBox11.Text = Convert.ToString(orderNo); }
}
And then in your code, everywhere you set orderNo
, change it to use OrderNo
to set it through a property.
Upvotes: 1