load runs sub progs

  • Thread starter Thread starter John
  • Start date Start date
J

John

when I am setting my values for a form in the Load sub, I set some of the
textbox and combobox values. this cuases their textchanged event to happen
and my subs run as if the text changed even though this is just the initial
load. should I be using a different event or a different way to set the
value?
 
Hi John,

Yes, even though you change the text of TextBox or the value of ComboBox in
the form's Load event handler, this will cause the TextBox's TextChanged
and ComboBox's TextChanged events to happen.

If you wouldn't like above events to happen when you set the text of
TextBox and the value of ComboBox in the form's Load event handler, you
could move the code of subscribing these events to behind the code of
setting the text of TextBox and the value of ComboBox.

It's something like below.

private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Text = ".....";
this.comboBox1.SelectedIndex = 1;
this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
this.comboBox1.TextChanged += new EventHandler(comboBox1_TextChanged);

}

If you have subscribed these events by designer, you should remove them
from Properties window. To do this, select the TextBox on the form and
click the Events button in Properties window. Go to the TextChanged node
and clear the text (e.g textBox1_TextChanged) at this node.

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top