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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Value of checked checkboxes in a form

Value of checked checkboxes in a form

Scheduled Pinned Locked Moved C#
csharpcomhelpquestion
10 Posts 6 Posters 2 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.
  • H Offline
    H Offline
    Het2109
    wrote on last edited by
    #1

    I have few checkboxes in my form, and i want to get only those which are checked. Can this be done only in 1 line of code? As i know the loop to execute and get the checked values. Thanks in advance for your help.

    Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

    P P E 3 Replies Last reply
    0
    • H Het2109

      I have few checkboxes in my form, and i want to get only those which are checked. Can this be done only in 1 line of code? As i know the loop to execute and get the checked values. Thanks in advance for your help.

      Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      What's a line of code? If you encapsulate the details in a method you need only use that method.

      H P 2 Replies Last reply
      0
      • P PIEBALDconsult

        What's a line of code? If you encapsulate the details in a method you need only use that method.

        H Offline
        H Offline
        Het2109
        wrote on last edited by
        #3

        What i mean to say, is it possible to do it without a loop only with 1 line of code ?

        Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

        C P 2 Replies Last reply
        0
        • H Het2109

          What i mean to say, is it possible to do it without a loop only with 1 line of code ?

          Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Only if the line is really long, or calls a method that does a loop.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          1 Reply Last reply
          0
          • H Het2109

            What i mean to say, is it possible to do it without a loop only with 1 line of code ?

            Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Het2109 wrote:

            without a loop

            Perhaps.

            Het2109 wrote:

            with 1 line of code

            Perhaps not. How about adding a collection for the checked CheckBoxes to your form, and having the CheckedChanged event handler(s) add and remove them as appropriate?

            1 Reply Last reply
            0
            • H Het2109

              I have few checkboxes in my form, and i want to get only those which are checked. Can this be done only in 1 line of code? As i know the loop to execute and get the checked values. Thanks in advance for your help.

              Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              Het2109 wrote:

              few checkboxes in my form, and i want to get only those which are checked. Can this be done only in 1 line of code?

              Probably only if you use a loop or as a procedure like CheckForCheckedCheckBoxes();. What is it that you want to do with the checked checkboxes when you find them?

              "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

              1 Reply Last reply
              0
              • P PIEBALDconsult

                What's a line of code? If you encapsulate the details in a method you need only use that method.

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #7

                PIEBALDconsult wrote:

                What's a line of code?

                Things that might make a computer do what you want it to. Something the PHB has no true understanding what it is.

                "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

                1 Reply Last reply
                0
                • H Het2109

                  I have few checkboxes in my form, and i want to get only those which are checked. Can this be done only in 1 line of code? As i know the loop to execute and get the checked values. Thanks in advance for your help.

                  Het Waghela :)Be Humble in Victory and Strong in Defeat.:) Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links

                  E Offline
                  E Offline
                  Ennis Ray Lynch Jr
                  wrote on last edited by
                  #8

                  Add an event to the CheckChanged event. In that code you can use code to populate a list. The one line of code would be: someMemberList.Add((CheckBox)sender); In the event. The easiest method, however, is just the if statements. You mentioned a loop so maybe this is ASP.NET so there is a complicated simple way to do it by getting the submitted value by the id of the check box so long as every check box has the same id.

                  Need a C# Consultant? I'm available.
                  Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                  C 1 Reply Last reply
                  0
                  • E Ennis Ray Lynch Jr

                    Add an event to the CheckChanged event. In that code you can use code to populate a list. The one line of code would be: someMemberList.Add((CheckBox)sender); In the event. The easiest method, however, is just the if statements. You mentioned a loop so maybe this is ASP.NET so there is a complicated simple way to do it by getting the submitted value by the id of the check box so long as every check box has the same id.

                    Need a C# Consultant? I'm available.
                    Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                    C Offline
                    C Offline
                    ChandraRam
                    wrote on last edited by
                    #9

                    Ennis Ray Lynch, Jr. wrote:

                    Add an event to the CheckChanged event. In that code you can use code to populate a list. The one line of code would be: someMemberList.Add((CheckBox)sender); In the event.

                    What about repeated clicks? Check - uncheck - check :)

                    E 1 Reply Last reply
                    0
                    • C ChandraRam

                      Ennis Ray Lynch, Jr. wrote:

                      Add an event to the CheckChanged event. In that code you can use code to populate a list. The one line of code would be: someMemberList.Add((CheckBox)sender); In the event.

                      What about repeated clicks? Check - uncheck - check :)

                      E Offline
                      E Offline
                      Ennis Ray Lynch Jr
                      wrote on last edited by
                      #10

                      object o = ((Checkbox)sender).Checked ? list.Remove((CheckBox)sender) : list.Add((CheckBox)sender); Just might work, or some variation thereof :) There is always a way to write bad code. Use a hash to avoid duplicates if it really matters.

                      Need a C# Consultant? I'm available.
                      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                      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