Binding a GroupBox

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

    #1

    Binding a GroupBox

    Hi everybody,
    I posted this question before but got a strange response from someone.
    Anyways, is it possible to bind a GroupBox that includes multiple check
    boxes to a column in a SQL database? Yes or No.

    If it's yes, when the user checks one of these check boxes, what value will
    be stored in the column? I'm really confused about that. Please help.
    If there is any white paper about this, it will also be helpful.
    --
    TS
  • Jim Underwood

    #2
    Re: Binding a GroupBox

    TS,
    I believe the answer you got for the first post was no, this cannot be done
    as you describe it.

    You probably need to manually assign a value to each checkbox. Associating
    specific database vales to each checkbox when loading/saving data would also
    have to be done manually, probably by looping through the check boxes and
    checking each one as you load/save data. This isn't too bad if you know in
    advance what checkboxes you want to display.

    If you want to add checkboxes based on data, this can be done
    programmaticall y, but I am not the one to explain how to do it. For
    example, you have a field "fruit" in the database with 3 values (apple,
    orange, grape), and you want 3 checkboxes. Someone adds a value (peach) to
    the database, now you want the app to display 4 checkboxes. Is this what
    you are trying to do?

    AFAIK means As Far As I Know.


    "TS" <TS@discussions .microsoft.com> wrote in message
    news:08F67FA7-9F17-48C3-8571-0F10E4BC11C4@mi crosoft.com...[color=blue]
    > Hi everybody,
    > I posted this question before but got a strange response from someone.
    > Anyways, is it possible to bind a GroupBox that includes multiple check
    > boxes to a column in a SQL database? Yes or No.
    >
    > If it's yes, when the user checks one of these check boxes, what value[/color]
    will[color=blue]
    > be stored in the column? I'm really confused about that. Please help.
    > If there is any white paper about this, it will also be helpful.
    > --
    > TS[/color]


    Comment

    • TS

      #3
      Re: Binding a GroupBox

      Thanks for your prompt response.
      To answer you, let's say the field "fruit" has 3 values (apple, orange,
      grape), and I have 3 check boxes for each one of them. I want the user when
      selecting the check box for "grape" and hit the save button, the word "grape"
      gets saved in the database. Now, as you mention I can use a loop to check the
      checked propety for the check boxes and puch to a database a value based on
      the user's selection, but how to loop through the checkboxes included in the
      groupbox? And how the word "grape" in the database will be translated to (a
      check box that is checked) when users view the data in their windows form.
      --
      TS


      "Jim Underwood" wrote:
      [color=blue]
      > TS,
      > I believe the answer you got for the first post was no, this cannot be done
      > as you describe it.
      >
      > You probably need to manually assign a value to each checkbox. Associating
      > specific database vales to each checkbox when loading/saving data would also
      > have to be done manually, probably by looping through the check boxes and
      > checking each one as you load/save data. This isn't too bad if you know in
      > advance what checkboxes you want to display.
      >
      > If you want to add checkboxes based on data, this can be done
      > programmaticall y, but I am not the one to explain how to do it. For
      > example, you have a field "fruit" in the database with 3 values (apple,
      > orange, grape), and you want 3 checkboxes. Someone adds a value (peach) to
      > the database, now you want the app to display 4 checkboxes. Is this what
      > you are trying to do?
      >
      > AFAIK means As Far As I Know.
      >
      >
      > "TS" <TS@discussions .microsoft.com> wrote in message
      > news:08F67FA7-9F17-48C3-8571-0F10E4BC11C4@mi crosoft.com...[color=green]
      > > Hi everybody,
      > > I posted this question before but got a strange response from someone.
      > > Anyways, is it possible to bind a GroupBox that includes multiple check
      > > boxes to a column in a SQL database? Yes or No.
      > >
      > > If it's yes, when the user checks one of these check boxes, what value[/color]
      > will[color=green]
      > > be stored in the column? I'm really confused about that. Please help.
      > > If there is any white paper about this, it will also be helpful.
      > > --
      > > TS[/color]
      >
      >
      >[/color]

      Comment

      • ECathell

        #4
        Re: Binding a GroupBox

        use events instead. Have a variable that is strFruit. If you have a set
        amount you can even use enums to make it easier

        public enum FruitType
        "Banana"
        "Cherry"
        "Peach"

        private mFruit as fruitType
        Public Property Fruit as FruitType
        ....
        ....

        ....

        then in the checkchanged event have the handler change the value of the
        variable. Then pass the variable to your dataprovider and write the value to
        your database.


        --
        --Eric Cathell, MCSA
        "TS" <TS@discussions .microsoft.com> wrote in message
        news:DFA5148F-8680-43DD-9DF0-F3951E5A3A05@mi crosoft.com...[color=blue]
        > Thanks for your prompt response.
        > To answer you, let's say the field "fruit" has 3 values (apple, orange,
        > grape), and I have 3 check boxes for each one of them. I want the user
        > when
        > selecting the check box for "grape" and hit the save button, the word
        > "grape"
        > gets saved in the database. Now, as you mention I can use a loop to check
        > the
        > checked propety for the check boxes and puch to a database a value based
        > on
        > the user's selection, but how to loop through the checkboxes included in
        > the
        > groupbox? And how the word "grape" in the database will be translated to
        > (a
        > check box that is checked) when users view the data in their windows form.
        > --
        > TS
        >
        >
        > "Jim Underwood" wrote:
        >[color=green]
        >> TS,
        >> I believe the answer you got for the first post was no, this cannot be
        >> done
        >> as you describe it.
        >>
        >> You probably need to manually assign a value to each checkbox.
        >> Associating
        >> specific database vales to each checkbox when loading/saving data would
        >> also
        >> have to be done manually, probably by looping through the check boxes and
        >> checking each one as you load/save data. This isn't too bad if you know
        >> in
        >> advance what checkboxes you want to display.
        >>
        >> If you want to add checkboxes based on data, this can be done
        >> programmaticall y, but I am not the one to explain how to do it. For
        >> example, you have a field "fruit" in the database with 3 values (apple,
        >> orange, grape), and you want 3 checkboxes. Someone adds a value (peach)
        >> to
        >> the database, now you want the app to display 4 checkboxes. Is this what
        >> you are trying to do?
        >>
        >> AFAIK means As Far As I Know.
        >>
        >>
        >> "TS" <TS@discussions .microsoft.com> wrote in message
        >> news:08F67FA7-9F17-48C3-8571-0F10E4BC11C4@mi crosoft.com...[color=darkred]
        >> > Hi everybody,
        >> > I posted this question before but got a strange response from someone.
        >> > Anyways, is it possible to bind a GroupBox that includes multiple check
        >> > boxes to a column in a SQL database? Yes or No.
        >> >
        >> > If it's yes, when the user checks one of these check boxes, what value[/color]
        >> will[color=darkred]
        >> > be stored in the column? I'm really confused about that. Please help.
        >> > If there is any white paper about this, it will also be helpful.
        >> > --
        >> > TS[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        • Jim Underwood

          #5
          Re: Binding a GroupBox

          Create a group box and put 3 checkboxes inside it, then add this code to
          your project. This will loop through all the objects inside the group box.
          When loading from or saving to the database, use the .text property of the
          checkbox to determine whether or not it should be checked, or what value
          should be returned when it is checked.

          Private Sub testgroupbox()
          Dim mycontrol As Windows.Forms.C ontrol
          Dim myCheckbox As New Windows.Forms.C heckBox
          For Each mycontrol In GroupBox1.Contr ols
          If mycontrol.GetTy pe Is myCheckbox.GetT ype Then
          myCheckbox = mycontrol
          MsgBox(myCheckb ox.Name & " = " & myCheckbox.Text )
          End If
          Next
          End Sub

          "TS" <TS@discussions .microsoft.com> wrote in message
          news:DFA5148F-8680-43DD-9DF0-F3951E5A3A05@mi crosoft.com...[color=blue]
          > Thanks for your prompt response.
          > To answer you, let's say the field "fruit" has 3 values (apple, orange,
          > grape), and I have 3 check boxes for each one of them. I want the user[/color]
          when[color=blue]
          > selecting the check box for "grape" and hit the save button, the word[/color]
          "grape"[color=blue]
          > gets saved in the database. Now, as you mention I can use a loop to check[/color]
          the[color=blue]
          > checked propety for the check boxes and puch to a database a value based[/color]
          on[color=blue]
          > the user's selection, but how to loop through the checkboxes included in[/color]
          the[color=blue]
          > groupbox? And how the word "grape" in the database will be translated to[/color]
          (a[color=blue]
          > check box that is checked) when users view the data in their windows form.
          > --
          > TS
          >
          >
          > "Jim Underwood" wrote:
          >[color=green]
          > > TS,
          > > I believe the answer you got for the first post was no, this cannot be[/color][/color]
          done[color=blue][color=green]
          > > as you describe it.
          > >
          > > You probably need to manually assign a value to each checkbox.[/color][/color]
          Associating[color=blue][color=green]
          > > specific database vales to each checkbox when loading/saving data would[/color][/color]
          also[color=blue][color=green]
          > > have to be done manually, probably by looping through the check boxes[/color][/color]
          and[color=blue][color=green]
          > > checking each one as you load/save data. This isn't too bad if you know[/color][/color]
          in[color=blue][color=green]
          > > advance what checkboxes you want to display.
          > >
          > > If you want to add checkboxes based on data, this can be done
          > > programmaticall y, but I am not the one to explain how to do it. For
          > > example, you have a field "fruit" in the database with 3 values (apple,
          > > orange, grape), and you want 3 checkboxes. Someone adds a value (peach)[/color][/color]
          to[color=blue][color=green]
          > > the database, now you want the app to display 4 checkboxes. Is this[/color][/color]
          what[color=blue][color=green]
          > > you are trying to do?
          > >
          > > AFAIK means As Far As I Know.
          > >
          > >
          > > "TS" <TS@discussions .microsoft.com> wrote in message
          > > news:08F67FA7-9F17-48C3-8571-0F10E4BC11C4@mi crosoft.com...[color=darkred]
          > > > Hi everybody,
          > > > I posted this question before but got a strange response from someone.
          > > > Anyways, is it possible to bind a GroupBox that includes multiple[/color][/color][/color]
          check[color=blue][color=green][color=darkred]
          > > > boxes to a column in a SQL database? Yes or No.
          > > >
          > > > If it's yes, when the user checks one of these check boxes, what value[/color]
          > > will[color=darkred]
          > > > be stored in the column? I'm really confused about that. Please help.
          > > > If there is any white paper about this, it will also be helpful.
          > > > --
          > > > TS[/color]
          > >
          > >
          > >[/color][/color]


          Comment

          • YYZ

            #6
            Re: Binding a GroupBox

            > To answer you, let's say the field "fruit" has 3 values (apple, orange,[color=blue]
            > grape), and I have 3 check boxes for each one of them.[/color]

            Do you really want checkboxes? How about Radio Buttons instead. If
            the user can only choose one of the 3, then radio buttons is what you
            should use. If they can choose 0 or more then you should use
            checkboxes.

            If you DO need checkboxes, because they can choose grape and orange at
            the same time, then you need fields in the DB for each fruit type -- or
            a separate table with a fruit description and a value to indicate yes,
            the user chose it, or no, they didn't choose it.

            See what I mean?

            If you do that, then I think your binding issue will kind of take care
            of itself. However, I'm ultra-new to .Net, and in VB6 I never bound
            anything, so don't listen to me on that topic. But what I said about
            checkboxes vs. radio buttons still holds up, though...

            Matt

            Comment

            Working...