Binding a GroupBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
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
programmatically, 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.
 
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.
 
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.
 
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.Control
Dim myCheckbox As New Windows.Forms.CheckBox
For Each mycontrol In GroupBox1.Controls
If mycontrol.GetType Is myCheckbox.GetType Then
myCheckbox = mycontrol
MsgBox(myCheckbox.Name & " = " & myCheckbox.Text)
End If
Next
End Sub
 
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top