-
Apr 26th, 2006, 09:07 AM
#1
Thread Starter
PowerPoster
**RESOLVED** [2005] Having issues with radio buttons
I finding that forms (that were upgraded from VB6) are setting radio buttons to TRUE when the form loads. I have the value set to FALSE in the designer, yet when the form loads, the radio button fires. I got around this on one form by moving all the code from the CHANGE event to the CLICK event. However, the form I am working on now has groups of radio buttons. I can't just do the same movement of code because of the way VB2005 is doing indexes.
Current code:
VB Code:
'UPGRADE_WARNING: Event optAss.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
Private Sub optAss_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles optAss.CheckedChanged
If eventSender.Checked Then
Dim Index As Short = optAss.GetIndex(eventSender)
Select Case Index
Case 0 'tool to machine
glbTransactiontype.Value = "A"
Case 1 'tool to stock #
glbTransactiontype.Value = "B"
Case 2 'tool from machine
glbTransactiontype.Value = "C"
Case 3 'tool from stock #
glbTransactiontype.Value = "D"
End Select
frmAss.Show()
End If
End Sub
I could move this to the CLICK event if I could figure out how to test the index value in VB2005.
Last edited by Pasvorto; Apr 26th, 2006 at 12:11 PM.
-
Apr 26th, 2006, 09:31 AM
#2
Re: [2005] Having issues with radio buttons
don't you see the comment the upgrade wizard provided?
The reason is that when the form is created, it sets all the properties of its controls, and when it sets the checked property of the radiobutton, the event fires...
a simple work around is to check to see if the form is visible in the event, and only perform the actions if the form is visible, since when the form is being initialized, it won't be visible...
oh and nice radio button name
-
Apr 26th, 2006, 09:58 AM
#3
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
I saw the comment. I can't figure out how to access the link it provides. The warning said it "may" fire; it does fire. I will try the form visible code. I don't understand why it would set the value to TRUE, but there is a lot about .NET that I don't understand.
-
Apr 26th, 2006, 10:35 AM
#4
Re: [2005] Having issues with radio buttons
Just mouse over the link and ctrl+click it and it will bring you to the help topic its talking about (if you installed the MSDN help on your PC)
the work around they give is to use a variable switch to indicate if the form is initializing or not.. its the same idea as the form visible thing.. I just try to save variables wherever I can..
The idea is the same, use some sort of boolean to determine if the event should process its code or not, based on if the form is being initialized, or if the the user actually clicked the radio button....
-
Apr 26th, 2006, 10:47 AM
#5
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
I tried the ctrl-click. I get
Sorry, no topics were found for the selected link.
Keywords =
IndexMoniker =
Source URL =
=====
I tried this
VB Code:
Private Sub frmSetup_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Me.SetBounds(VB6.TwipsToPixelsX((VB6.PixelsToTwipsX(MDIForm1.Width) - VB6.PixelsToTwipsX(Me.Width)) / 2), VB6.TwipsToPixelsY(100), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y) '(MDIForm1.Height - frmSETUP.Height) / 2
Me.Width = 330
Me.Height = 348
Dim x As Short
For x = 0 To 3
optAss(x).checked = False
Next x
For x = 0 To 2
optMachine(x).Checked = False
optStock(x).Checked = False
optTool(x).Checked = False
Next x
End Sub
It processes that code and thn fallsin to this:
VB Code:
'UPGRADE_WARNING: Event optMachine.CheckedChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
Private Sub optMachine_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles optMachine.CheckedChanged
If Me.Visible = True Then
If eventSender.Checked Then
Dim Index As Short = optMachine.GetIndex(eventSender)
Select Case Index
Case 0
glbTransactiontype.Value = "A"
frmMachine.Show()
Case 1
glbTransactiontype.Value = "D"
frmMachine.Show()
Case 2
glbTransactiontype.Value = "C"
frmMachine.Show()
End Select
End If
End If
End Sub
You will note the "Me.visible" test. It is true at this point and the Machine screen fires up. (optAss was for the Assembly screen, BTW). So, somewhere between the form load end and the optMachine change event, the value is getting set to TRUE. Am I missing an option to show "hidden" code somewhere?
-
Apr 26th, 2006, 10:56 AM
#6
Re: [2005] Having issues with radio buttons
well yeah there is some hidden code.. in the solution explorer you need to select "Show All Files" (its one of the icons at the top of the solution explorer) and you will notice your form has a + sign next to it. Expand that and you will see your formname.designer.vb
this is where all the IDE generated stuff about your form goes, to reduce the clutter of your code (this is something new to VB2005, and its called a partial class)
but I have to wonder why you are running the code
VB Code:
For x = 0 To 3
optAss(x).checked = False
Next x
at all, why not just set all of the checked properties to false at design time and be done with it?
-
Apr 26th, 2006, 11:10 AM
#7
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
I do have them all set to FALSE at design time. I put that code in to reset the values if they had been set by hidden code. I was trying to "force" them to FALSE. However, they are getting set to TRUE after that.
-
Apr 26th, 2006, 11:16 AM
#8
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
Update... I added a textbox to the screen and set the Tab Stop to 0. Now the radio button doesn't fire. It was the first tab stop on the screen. So it appears that it is getting set to TRUE when it gets focus during the form load event.
-
Apr 26th, 2006, 11:25 AM
#9
Re: [2005] Having issues with radio buttons
that makes sense.. it was getting focus, which was causing it to fire..
so is it resolved?
-
Apr 26th, 2006, 11:39 AM
#10
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
Is it resolved? Only to the extent that I can put an invisible text box on the form to keep the button from getting 'initial' focus on form load. I feel that I am treating the symptom and ignoring the disease. It would be, in my humble opinion, an 'inelegant' solution.
-
Apr 26th, 2006, 11:44 AM
#11
Re: [2005] Having issues with radio buttons
oh.. then instead of using the .visible thing... use a variable. it will make your life easier..
in the general declarations, put
Private _IsFormInitalizing as boolean = true
then in your checkchanged event, instead of checking if the form is visible, on run the code if _IsFormInitalizing = false
in the very last line of your form load event set _IsFormInitalizing to False, so that future clicks of the randio button will perform the code in the event...
-
Apr 26th, 2006, 12:06 PM
#12
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
I tried that and traced through it. At the end of the form load event I set IsFormInitalizing = false. The first line in the readio button code checks that. However, by that point I have set it to false, so the radio button code runs. I am beginning to think that the (bogus) textbox is going to be the short-term answer.
-
Apr 26th, 2006, 12:10 PM
#13
Thread Starter
PowerPoster
Re: [2005] Having issues with radio buttons
I think I've got it..
VB Code:
If IsFormInitalizing = False Then
If eventSender.Checked Then
Dim Index As Short = optMachine.GetIndex(eventSender)
Select Case Index
Case 0
glbTransactiontype.Value = "A"
frmMachine.Show()
Case 1
glbTransactiontype.Value = "D"
frmMachine.Show()
Case 2
glbTransactiontype.Value = "C"
frmMachine.Show()
End Select
End If
Else
IsFormInitalizing = False
End If
-
Apr 26th, 2006, 12:11 PM
#14
Thread Starter
PowerPoster
Re: **RESOLVED** [2005] Having issues with radio buttons
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|