Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. radiobutton and bool

radiobutton and bool

Scheduled Pinned Locked Moved C#
csharphelp
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kabutar
    wrote on last edited by
    #1

    HI, I have two radio buttons male and female in windows form.... this is my code..... whatever i do it will only display female which ever radio button i clicked.... i suspect there is some pblm with my bool... can anybody help me plzzz bool flag=true; public Form1() { InitializeComponent(); } private void txtBranch_TextChanged(object sender, EventArgs e) { } private void btnRadio_Click(object sender, EventArgs e) { if (flag==true) { txtBranch.Text = rdoMale.Text; } if(flag==false) { txtBranch.Text = rdoFemale.Text; } } } } thanks in advance

    C#

    N S 2 Replies Last reply
    0
    • K kabutar

      HI, I have two radio buttons male and female in windows form.... this is my code..... whatever i do it will only display female which ever radio button i clicked.... i suspect there is some pblm with my bool... can anybody help me plzzz bool flag=true; public Form1() { InitializeComponent(); } private void txtBranch_TextChanged(object sender, EventArgs e) { } private void btnRadio_Click(object sender, EventArgs e) { if (flag==true) { txtBranch.Text = rdoMale.Text; } if(flag==false) { txtBranch.Text = rdoFemale.Text; } } } } thanks in advance

      C#

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      kabutar wrote:

      if(flag==false) { txtBranch.Text = rdoFemale.Text; }

      You are not setting flag=false anywhere in the code


      My Website | Ask smart questions

      K 1 Reply Last reply
      0
      • K kabutar

        HI, I have two radio buttons male and female in windows form.... this is my code..... whatever i do it will only display female which ever radio button i clicked.... i suspect there is some pblm with my bool... can anybody help me plzzz bool flag=true; public Form1() { InitializeComponent(); } private void txtBranch_TextChanged(object sender, EventArgs e) { } private void btnRadio_Click(object sender, EventArgs e) { if (flag==true) { txtBranch.Text = rdoMale.Text; } if(flag==false) { txtBranch.Text = rdoFemale.Text; } } } } thanks in advance

        C#

        S Offline
        S Offline
        Spunky Coder
        wrote on last edited by
        #3

        if you have two radio buttons then btnRadio_Click(object sender, EventArgs e) corresponds to which radio button is it for both ?

        Koushik

        1 Reply Last reply
        0
        • N N a v a n e e t h

          kabutar wrote:

          if(flag==false) { txtBranch.Text = rdoFemale.Text; }

          You are not setting flag=false anywhere in the code


          My Website | Ask smart questions

          K Offline
          K Offline
          kabutar
          wrote on last edited by
          #4

          but navneeth isnt the bools default value always false.....? can you just alter my complete code for me so that i can understand it better if you dont mind.... or is there anyother way of doing by not using the bool ie something like if(rdobuttonmale.selected) { txtBranch.Text = rdoMale.Text; } if(rdobuttonfemale.selected) { txtBranch.Text = rdoFemale.Text; } my basic purpose is the same ie the textbox should display the selected radio button....:) thanking you

          C#

          N 1 Reply Last reply
          0
          • K kabutar

            but navneeth isnt the bools default value always false.....? can you just alter my complete code for me so that i can understand it better if you dont mind.... or is there anyother way of doing by not using the bool ie something like if(rdobuttonmale.selected) { txtBranch.Text = rdoMale.Text; } if(rdobuttonfemale.selected) { txtBranch.Text = rdoFemale.Text; } my basic purpose is the same ie the textbox should display the selected radio button....:) thanking you

            C#

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            But I see only one event here. Write two events for both radio buttons, and assign the textbox value in those events. No need of using the flag


            My Website | Ask smart questions

            K 1 Reply Last reply
            0
            • N N a v a n e e t h

              But I see only one event here. Write two events for both radio buttons, and assign the textbox value in those events. No need of using the flag


              My Website | Ask smart questions

              K Offline
              K Offline
              kabutar
              wrote on last edited by
              #6

              Awesome now i got it working........now its working fine.....thankyou guys

              C#

              K 1 Reply Last reply
              0
              • K kabutar

                Awesome now i got it working........now its working fine.....thankyou guys

                C#

                K Offline
                K Offline
                kabutar
                wrote on last edited by
                #7

                hi, i have one more doubt if i want to use multiple windows that form1 will have datagrid and form2 will have textboxes and if i want to display the details entered in form2 in the datagrid in form1 .....do i need to use delegates or is there any other easy way of doing it..... :) thanks

                C#

                N 1 Reply Last reply
                0
                • K kabutar

                  hi, i have one more doubt if i want to use multiple windows that form1 will have datagrid and form2 will have textboxes and if i want to display the details entered in form2 in the datagrid in form1 .....do i need to use delegates or is there any other easy way of doing it..... :) thanks

                  C#

                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #8

                  kabutar wrote:

                  do i need to use delegates or is there any other easy way of doing it.....

                  Delegates are always a good practice. Alternatively you can overload form2 constructor and pass form1 object there while invoking form2. Use this object to set value back to form1.


                  My Website | Ask smart questions

                  K 1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    kabutar wrote:

                    do i need to use delegates or is there any other easy way of doing it.....

                    Delegates are always a good practice. Alternatively you can overload form2 constructor and pass form1 object there while invoking form2. Use this object to set value back to form1.


                    My Website | Ask smart questions

                    K Offline
                    K Offline
                    kabutar
                    wrote on last edited by
                    #9

                    Thanks again will try with delegate first

                    C#

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups