Databinding Checkboxes

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

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
 
You can bind the "Checked" property of each checkbox to the
corresponding datacolumn in the Datatable of your Dataset.
 
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?
 
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.
 
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?
 
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,

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.checked = 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
 
Cor,

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

Thanks!
Mike
 
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,

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]
 
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
 

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