disabling controls by checking off a radio button when the form loads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • helpful sql

    #1

    disabling controls by checking off a radio button when the form loads

    Hi,
    I have 2 radio buttons on my Windows form control. The radio button's
    CheckedChanged event disables or enables other controls on the form based on
    the value of the Checked property.
    When the form loads, I want to check off one of the radio buttons. So I
    put the code to check off my radio button in the form's load event. But the
    CheckedChanged even is not firing.

    Private Sub ActivityList_Lo ad(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    ' check the Unscheduled Activity radio button

    rdoUnscheduledA ctivity.Checked = True

    End Sub

    This code is not firing the CheckedChanged event of the radio button.

    Any help will be appreciated.

    Thanks in advance...


  • yogeshprabhu

    #2
    RE: disabling controls by checking off a radio button when the form lo

    Only thing I can think of is if rdoUnscheduledA ctivity's Checked property is
    set to True at the design time then in Form Load event setting it again to
    True will not fire that event.

    Comment

    • Cerebrus

      #3
      Re: disabling controls by checking off a radio button when the form loads

      Hi,

      You did not post the code that you're using as a handler for your
      CheckedChanged event.

      Two possible reasons come to my mind, which might explain the problem :

      1. The Eventhandler is not wired to the Event. i.e., the method
      Private Sub rdoUnscheduledA ctivity_Checked Changed() does not have a
      Handles clause to connect it to the event.

      2. If the radio button is already checked and you set it's checked
      property to True, the CheckedChanged event won't fire. Though, in this
      case, it probably won't be possible, since even if you set the Checked
      property of the Radio button to True in Design mode, the event will
      still fire when InitializeCompo nent sets that setting. (Pardon the long
      sentence.)

      Regards,

      Cerebrus.

      Comment

      • James Park

        #4
        Re: disabling controls by checking off a radio button when the form loads

        "Cerebrus" <zorg007@sify.c om> wrote in message
        news:1143845708 .169478.146360@ u72g2000cwu.goo glegroups.com.. .[color=blue]
        > Hi,
        >
        > You did not post the code that you're using as a handler for your
        > CheckedChanged event.
        >
        > Two possible reasons come to my mind, which might explain the problem :
        >
        > 1. The Eventhandler is not wired to the Event. i.e., the method
        > Private Sub rdoUnscheduledA ctivity_Checked Changed() does not have a
        > Handles clause to connect it to the event.
        >
        > 2. If the radio button is already checked and you set it's checked
        > property to True, the CheckedChanged event won't fire. Though, in this
        > case, it probably won't be possible, since even if you set the Checked
        > property of the Radio button to True in Design mode, the event will
        > still fire when InitializeCompo nent sets that setting. (Pardon the long
        > sentence.)[/color]

        Actually, #2 is possible. The Designer sets properties before adding event
        handlers in InitializeCompo nent.


        Comment

        • Lebesgue

          #5
          Re: disabling controls by checking off a radio button when the form loads

          Please note that crossposting is considered rude. Please note that this has
          nothing to do with the C# programming language. When crossposting any of
          your problems again, please omit the csharp group.
          Thanks.

          "helpful sql" <nospam@stopspa m.com> wrote in message
          news:%23DPaQOQV GHA.5004@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > Hi,
          > I have 2 radio buttons on my Windows form control. The radio button's
          > CheckedChanged event disables or enables other controls on the form based
          > on the value of the Checked property.
          > When the form loads, I want to check off one of the radio buttons. So I
          > put the code to check off my radio button in the form's load event. But
          > the CheckedChanged even is not firing.
          >
          > Private Sub ActivityList_Lo ad(ByVal sender As System.Object, ByVal e As
          > System.EventArg s) Handles MyBase.Load
          >
          > ' check the Unscheduled Activity radio button
          >
          > rdoUnscheduledA ctivity.Checked = True
          >
          > End Sub
          >
          > This code is not firing the CheckedChanged event of the radio button.
          >
          > Any help will be appreciated.
          >
          > Thanks in advance...
          >
          >[/color]


          Comment

          • Cerebrus

            #6
            Re: disabling controls by checking off a radio button when the form loads

            Hi James,
            [color=blue][color=green]
            >> Actually, #2 is possible. The Designer sets properties before adding event
            >> handlers in InitializeCompo nent.[/color][/color]

            Could you elaborate on how #2 is possible ? I actually tried this. I
            set the Checked property to True in Design mode. Then implemented an
            Event handler for the CheckedChanged event. I then set breakpoints
            within the InitializeCompo nent, where the property is set, and within
            the Eventhandler.

            As I have mentioned, the program breaks within the Initialize
            component, and even before proceeding to the next line, the
            CheckedChanged event is raised.

            Regards,

            Cerebrus.

            Comment

            • James Park

              #7
              Re: disabling controls by checking off a radio button when the form loads

              "Cerebrus" <zorg007@sify.c om> wrote in message
              news:1143884120 .449070.153150@ i39g2000cwa.goo glegroups.com.. .[color=blue]
              > Hi James,
              >[color=green][color=darkred]
              >>> Actually, #2 is possible. The Designer sets properties before adding
              >>> event
              >>> handlers in InitializeCompo nent.[/color][/color]
              >
              > Could you elaborate on how #2 is possible ? I actually tried this. I
              > set the Checked property to True in Design mode. Then implemented an
              > Event handler for the CheckedChanged event. I then set breakpoints
              > within the InitializeCompo nent, where the property is set, and within
              > the Eventhandler.
              >
              > As I have mentioned, the program breaks within the Initialize
              > component, and even before proceeding to the next line, the
              > CheckedChanged event is raised.[/color]

              I did what you did and the event isn't raised. Looking at my
              InitializeCompo nent(), I can't see how it could.

              private void InitializeCompo nent()
              {
              // snip
              this.radioButto n1.Checked = true;
              // snip
              this.radioButto n1.CheckedChang ed += new
              System.EventHan dler(this.radio Button1_Checked Changed);
              // snip
              }

              If I hand-modify it and move the latter statement before the former, then
              the event goes off. But as it is, no go.

              Comment

              • James Park

                #8
                Re: disabling controls by checking off a radio button when the form loads

                "James Park" <fakename@fakea ddress.com> wrote in message
                news:4344F2E8-4A54-45C1-9C87-EB1DE07796D5@mi crosoft.com...[color=blue]
                > "Cerebrus" <zorg007@sify.c om> wrote in message
                > news:1143884120 .449070.153150@ i39g2000cwa.goo glegroups.com.. .[color=green]
                >> Hi James,
                >>[color=darkred]
                >>>> Actually, #2 is possible. The Designer sets properties before adding
                >>>> event
                >>>> handlers in InitializeCompo nent.[/color]
                >>
                >> Could you elaborate on how #2 is possible ? I actually tried this. I
                >> set the Checked property to True in Design mode. Then implemented an
                >> Event handler for the CheckedChanged event. I then set breakpoints
                >> within the InitializeCompo nent, where the property is set, and within
                >> the Eventhandler.
                >>
                >> As I have mentioned, the program breaks within the Initialize
                >> component, and even before proceeding to the next line, the
                >> CheckedChanged event is raised.[/color]
                >
                > I did what you did and the event isn't raised. Looking at my
                > InitializeCompo nent(), I can't see how it could.
                >
                > private void InitializeCompo nent()
                > {
                > // snip
                > this.radioButto n1.Checked = true;
                > // snip
                > this.radioButto n1.CheckedChang ed += new
                > System.EventHan dler(this.radio Button1_Checked Changed);
                > // snip
                > }
                >
                > If I hand-modify it and move the latter statement before the former, then
                > the event goes off. But as it is, no go.[/color]

                Whoops. Totally missed that the OP is using VB. I saw the thread from the
                csharp group and made a bad assumption.

                Comment

                • Cerebrus

                  #9
                  Re: disabling controls by checking off a radio button when the form loads

                  >>Whoops. Totally missed that the OP is using VB. I saw the thread from the[color=blue][color=green]
                  >> csharp group and made a bad assumption.[/color][/color]

                  Ah ! I suspected as much...

                  So Lebesgue's comments about cross-posting to newsgroups seem even more
                  appropriate.

                  Regards,

                  Cerebrus.

                  Comment

                  Working...