Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CheckedChanged event firing on form open

Status
Not open for further replies.

gleeb

IS-IT--Management
Feb 10, 2004
19
US
Hi all,
I know I have seen this discussed somewhere, but cannot find it for some reason. I'm using VB.NET 05.

Inside the CheckedChanged event for a checkbox on my form, I have some code to perform. I check the state of the box, and if it is checked I add a flag to a patient class.

Code:
        pt.NonCompliant = chkNonComp.Checked
        pt.Update()

The problem is that the event fires every time the form opens. How can I ignore this event until the check box actually changes?
Thanks
 
I've not experienced that problem with 2008, however two possible ways around it:

1: Add the CheckBox Checked handler in the FormLoad Event (using AddHandler) or ...

2:

Code:
Public Class Form1

	Private ImActive As Boolean = False

	Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

		If ImActive Then
			MessageBox.Show("CheckChanged Event")
		End If

	End Sub

	Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

		If Not ImActive Then ImActive = True

	End Sub
End Class


Hope this helps.


[vampire][bat]
 
Thanks. AddHandler worked like a charm and more elegant. I had used it elsewhere but couldn't remember that. I'm getting old I guess. Thanks again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top