Databinding Checkboxes

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

    #1

    Databinding Checkboxes

    My form has multiple checkboxes. The user can select any number of these
    checkboxes (including none). I have a table in my DB that would have one
    entry per checkbox if the checkbox has been checked. If it hasn't been
    checked, then the table will not have an entry.

    What is the best way to bind my checkboxes to that table (which is loaded
    into a dataset)?

    Thanks much!
    Mike


  • Jerry H.

    #2
    Re: Databinding Checkboxes

    You can bind the "Checked" property of each checkbox to the
    corresponding datacolumn in the Datatable of your Dataset.

    Comment

    • Jerry H.

      #3
      Re: Databinding Checkboxes

      Oops, sorry, I misread your post. did you mean to say that for each
      checkbox that is Checked, a row will be added to your database table?

      Comment

      • Rick Mogstad

        #4
        Re: Databinding Checkboxes

        You cant do that with the standard databinding. All controls will be bound
        to the single current record. You can use a grid, perhaps, but it will
        still be difficult.


        "Mike" <pcgurunospam@b ellsouth.net> wrote in message
        news:J2x3f.9$6l .3@bignews3.bel lsouth.net...[color=blue]
        > My form has multiple checkboxes. The user can select any number of these
        > checkboxes (including none). I have a table in my DB that would have one
        > entry per checkbox if the checkbox has been checked. If it hasn't been
        > checked, then the table will not have an entry.
        >
        > What is the best way to bind my checkboxes to that table (which is loaded
        > into a dataset)?
        >
        > Thanks much!
        > Mike
        >[/color]


        Comment

        • Mike

          #5
          Re: Databinding Checkboxes

          Yes, that is what I said.

          The simple binding (one for one) is straightforward . My question is how do I
          bind the checkbox to data that is not there?

          "Jerry H." <boilersrock@gm ail.com> wrote in message
          news:1129226475 .836347.208060@ g43g2000cwa.goo glegroups.com.. .[color=blue]
          > Oops, sorry, I misread your post. did you mean to say that for each
          > checkbox that is Checked, a row will be added to your database table?
          >[/color]


          Comment

          • Mike

            #6
            Re: Databinding Checkboxes

            Let me add some clarification.

            I'm not storing a boolean value in the database. The user checking the
            checkbox causes my code to create an entry in the table. The presence of
            this entry will drive the "checked" value the next time it is shown. In
            other words, if no entry exits, then the checkbox is not checked. If an
            entry exists, then the checkbox is checked.

            I'm thinking this may come down to me creating a new column for my table in
            the dataset and binding that column to the checked value. I would also need
            to add any missing rows. I definitely do not like this approach, although it
            could be done.

            Thanks very much for your help.


            "Mike" <pcgurunospam@b ellsouth.net> wrote in message
            news:rwx3f.37$6 l.8@bignews3.be llsouth.net...[color=blue]
            > Yes, that is what I said.
            >
            > The simple binding (one for one) is straightforward . My question is how do
            > I bind the checkbox to data that is not there?
            >
            > "Jerry H." <boilersrock@gm ail.com> wrote in message
            > news:1129226475 .836347.208060@ g43g2000cwa.goo glegroups.com.. .[color=green]
            >> Oops, sorry, I misread your post. did you mean to say that for each
            >> checkbox that is Checked, a row will be added to your database table?
            >>[/color]
            >
            >[/color]


            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Databinding Checkboxes

              Jerry,

              What is wrong, I do it in that way?

              :-)

              Cor


              Comment

              • Mike

                #8
                Re: Databinding Checkboxes

                Cor,

                I'm all ears (and eyes). Please expand my knowledgebase - I would greatly
                appreciate it!

                Thanks!
                Mike

                "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
                news:%23AhfuOC0 FHA.2064@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                > Jerry,
                >
                > What is wrong, I do it in that way?
                >
                > :-)
                >
                > Cor
                >[/color]


                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: Databinding Checkboxes

                  Mike,

                  You can not bind to nothing.

                  Therefore as you want it to do your way, than it is just old checking.

                  If mydatarow Is Nothing then
                  mycheckbox.chec ked = true
                  end if

                  And using the checkstate change event to create newrows.

                  Although this is in my opinion a strange and probably quick to spaghetti and
                  errors leading solution. (You have by instance to protect by disabling that
                  checkbox (what looks weird) the use of that checkbox again.

                  However just my thought,

                  Cor


                  Comment

                  • Mike

                    #10
                    Re: Databinding Checkboxes

                    Cor,

                    We agree - I do not prefer to handle it this way. I just don't know enough
                    to do it a better way. I'm thinking you might, though. :)

                    Can you offer me some suggestions?

                    Thanks!
                    Mike

                    "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
                    news:u%23rTQSC0 FHA.128@TK2MSFT NGP10.phx.gbl.. .[color=blue]
                    > Mike,
                    >
                    > You can not bind to nothing.
                    >
                    > Therefore as you want it to do your way, than it is just old checking.
                    >
                    > If mydatarow Is Nothing then
                    > mycheckbox.chec ked = true
                    > end if
                    >
                    > And using the checkstate change event to create newrows.
                    >
                    > Although this is in my opinion a strange and probably quick to spaghetti
                    > and errors leading solution. (You have by instance to protect by disabling
                    > that checkbox (what looks weird) the use of that checkbox again.
                    >
                    > However just my thought,
                    >
                    > Cor
                    >
                    >[/color]


                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: Databinding Checkboxes

                      Mike,

                      What if your user unchecks the checkbox, what is than the action?

                      Cor


                      "Mike" <pcgurunospam@b ellsouth.net> schreef in bericht
                      news:nQx3f.58$6 l.32@bignews3.b ellsouth.net...[color=blue]
                      > Cor,
                      >
                      > We agree - I do not prefer to handle it this way. I just don't know enough
                      > to do it a better way. I'm thinking you might, though. :)
                      >
                      > Can you offer me some suggestions?
                      >
                      > Thanks!
                      > Mike
                      >
                      > "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
                      > news:u%23rTQSC0 FHA.128@TK2MSFT NGP10.phx.gbl.. .[color=green]
                      >> Mike,
                      >>
                      >> You can not bind to nothing.
                      >>
                      >> Therefore as you want it to do your way, than it is just old checking.
                      >>
                      >> If mydatarow Is Nothing then
                      >> mycheckbox.chec ked = true
                      >> end if
                      >>
                      >> And using the checkstate change event to create newrows.
                      >>
                      >> Although this is in my opinion a strange and probably quick to spaghetti
                      >> and errors leading solution. (You have by instance to protect by
                      >> disabling that checkbox (what looks weird) the use of that checkbox
                      >> again.
                      >>
                      >> However just my thought,
                      >>
                      >> Cor
                      >>
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      • Mike

                        #12
                        Re: Databinding Checkboxes

                        Cor,

                        I'll try to give you more detail to help you understand what I am doing.

                        I'm trying to track records for a kid's club I'm involved with. Each child
                        works through books. The books have awards. Each award consists of a
                        variable number of sections.

                        Among other things (datepicker, combo box with names of children, etc.), the
                        form has the following:

                        <label with award name> <chkbox> <chkbox> <chkbox> ... [as many as
                        necessary for this award]

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: Databinding Checkboxes

                          Mike,

                          I took some time to make a sample for you in the way I would probably do it.
                          It are the basics not all things you ask have I implemented.



                          I hope this helps,

                          Cor


                          Comment

                          • Mike

                            #14
                            Re: Databinding Checkboxes

                            Thank you, Cor, for taking your time to help. I will review your sample
                            later today and let you know if it does what I need.

                            Thanks again!
                            Mike

                            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
                            news:uyr1twK0FH A.1132@TK2MSFTN GP10.phx.gbl...[color=blue]
                            > Mike,
                            >
                            > I took some time to make a sample for you in the way I would probably do
                            > it. It are the basics not all things you ask have I implemented.
                            >
                            > http://www.vb-tips.com/default.aspx?...4-d5f9861ba534
                            >
                            > I hope this helps,
                            >
                            > Cor
                            >[/color]


                            Comment

                            Working...