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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating A New Instance of a Form

Status
Not open for further replies.

smeeks

Programmer
Oct 7, 2003
31
US
I have a form with a some controls and events for those controls....when I create an instance of that form the controls (radio buttons) event fires before the form is even loaded. Then....after my form loads, when I click on the either control (in this case either of two radio buttons) the check_changed event fires TWICE!!! What am I doing wrong?

Shane
 
Sorry about that. I didn't paste it in.

for simplicity sake let's say I have a Child Form called Form1..
on this form is 2 radio buttons..

From the parent form I do:

Sub ShowTheForm()
dim NewForm1 as new Form1

NewForm1.ShowDialog()

End Sub


Here is the event that handles my radio buttons, it fires when the following code is hit in NewForm1:

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New() <----------after this line it fires


at this point the form is not even visible....
then once it does load, when I click one of my radio buttons the below event fires twice?


Private Sub radButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radLock.CheckedChanged, radUnlock.CheckedChanged

'lock or unlock the user
If Me.radLock.Checked Then
UserMod.LockOutUser = 1
Else
UserMod.UnLockUser = 2
End If


Hope all that makes sense.
 
Well, it fires twice because one becomes checked, and the other becomes unchecked, always together.

If you don't want your logic to occur that early for the CheckChanged event, then don't allow it. Control it with a boolean variable that says it ready, or something like that.
 
Also, it fires when the page loads because the event is bound before it sets the default checkd value for the item (i have run into this before).

Another option, besides the boolean flag, would be to capture the click events off the two radio buttons. Not sure if these are fired in the midle of the transfer ofwhich button has the checked ability or after the checked has been worked out, but if it is after then it should work just fine for your function above.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Thanks Guys....that helps me out!

Shane
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top