Results 1 to 14 of 14

Thread: **RESOLVED** [2005] Having issues with radio buttons

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved **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:
    1. '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"'
    2. Private Sub optAss_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles optAss.CheckedChanged
    3. If eventSender.Checked Then
    4.     Dim Index As Short = optAss.GetIndex(eventSender)
    5.     Select Case Index
    6.         Case 0 'tool to machine
    7.             glbTransactiontype.Value = "A"
    8.         Case 1 'tool to stock #
    9.             glbTransactiontype.Value = "B"
    10.         Case 2 'tool from machine
    11.             glbTransactiontype.Value = "C"
    12.         Case 3 'tool from stock #
    13.             glbTransactiontype.Value = "D"
    14.     End Select
    15.     frmAss.Show()
    16. End If
    17. 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.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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....

  5. #5

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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:
    1. Private Sub frmSetup_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    2.         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
    3. Me.Width = 330
    4. Me.Height = 348
    5. Dim x As Short
    6. For x = 0 To 3
    7.             optAss(x).checked = False
    8. Next x
    9. For x = 0 To 2
    10.             optMachine(x).Checked = False
    11.             optStock(x).Checked = False
    12.             optTool(x).Checked = False
    13.         Next x
    14. End Sub

    It processes that code and thn fallsin to this:
    VB Code:
    1. '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"'
    2.     Private Sub optMachine_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles optMachine.CheckedChanged
    3.         If Me.Visible = True Then
    4.             If eventSender.Checked Then
    5.                 Dim Index As Short = optMachine.GetIndex(eventSender)
    6.                 Select Case Index
    7.                     Case 0
    8.                         glbTransactiontype.Value = "A"
    9.                         frmMachine.Show()
    10.                     Case 1
    11.                         glbTransactiontype.Value = "D"
    12.                         frmMachine.Show()
    13.                     Case 2
    14.                         glbTransactiontype.Value = "C"
    15.                         frmMachine.Show()
    16.                 End Select
    17.             End If
    18.         End If
    19.     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?

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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:
    1. For x = 0 To 3
    2.             optAss(x).checked = False
    3. Next x

    at all, why not just set all of the checked properties to false at design time and be done with it?

  7. #7

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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.

  8. #8

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Having issues with radio buttons

    that makes sense.. it was getting focus, which was causing it to fire..

    so is it resolved?

  10. #10

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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.

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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...

  12. #12

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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.

  13. #13

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [2005] Having issues with radio buttons

    I think I've got it..

    VB Code:
    1. If IsFormInitalizing = False Then
    2.             If eventSender.Checked Then
    3.                 Dim Index As Short = optMachine.GetIndex(eventSender)
    4.                 Select Case Index
    5.                     Case 0
    6.                         glbTransactiontype.Value = "A"
    7.                         frmMachine.Show()
    8.                     Case 1
    9.                         glbTransactiontype.Value = "D"
    10.                         frmMachine.Show()
    11.                     Case 2
    12.                         glbTransactiontype.Value = "C"
    13.                         frmMachine.Show()
    14.                 End Select
    15.             End If
    16.         Else
    17.             IsFormInitalizing = False
    18.         End If

  14. #14

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: **RESOLVED** [2005] Having issues with radio buttons

    Thanks for all the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width