Binding RadioButtons

  • Thread starter Thread starter Nathan
  • Start date Start date
N

Nathan

Of all the VB.NET techniques I've learned so far, databinding has to be the
most complicated. I've got a problem (among others) with radio buttons. I
finally got the radion buttons to bind correctly when the form first loads,
but now changing them doesn't update the dataset properly.

I have on the form two group boxes, each with two radio buttons. The
Checked property of all four buttons are bound to Yes/No fields in an Access
database. When the form loads, the correct buttons are checked--the first
buttons in each group box. When I click the second button in one the boxes,
it becomes checked and the first one is unchecked. But then when I move the
focus, the first one
becomes checked again and the second unchecked. I've put a datagrid on the
form to see what's happening to the dataset -- when I click the second
button and move the focus, only the field for the second button in the
datagrid is updated, not the first. That is, the field for the second
button becomes checked, but the first one does not become unchecked.

If someone can make sense of what I'm saying and help me out, I'd really
appreciate it.
 
Ahh, well, I think that you need to do a DataAdatpter.Update() After
changing the status of the Radio buttons. Try it and let me know if this
does the trick.

Regards - OHM
 
["Followup-To:" header set to microsoft.public.dotnet.framework.windowsforms.databinding.]
Of all the VB.NET techniques I've learned so far, databinding has to be the
most complicated. I've got a problem (among others) with radio buttons. I
finally got the radion buttons to bind correctly when the form first loads,
but now changing them doesn't update the dataset properly.

This is pretty similar to the problem that gets mentioned a lot here
about databound combo boxes not updating when you set their index.

As a general guideline, databinding updates on UI user actions, not on
programmatic actions. If the user initiates an action on the control,
databinding will update the underlying data, but if you set the control
property in code, databinding will ignore the action (that's not 100%
true, but useful as a general rule).

When you click the second radio button, that's a UI action and the data
updates correctly. But the first radio button is set to unchecked
programmatically, and databinding ignores it. Why? I dunno, that's just
the way it is.

The workaround to this is to set the properties in your dataset
directly, either in a DataTable ColumnChanged event or in the Radio
Button click event or validate event.

Note followups changed...
 
Back
Top