[2008] Mixing BOUND controls with non-BOUND controls
We are binding most of our text boxes and dropdown boxes to a BINDING NAVIGATOR (with a DATA SOURCE of a DATA TABLE).
When the BN is clicked through the text boxes all change immediately.
We need to use some non-bound controls as well.
First one is 4 radio buttons that when clicked will change a single value in a DATA TABLE.
What would be the best method to do this? Should I track when the CURRENTCHANGED event occurs on the BINDING NAVIGATOR.
I'm thinking that I could trick this by BINDING the SINGLE FIELD to a HIDDEN TEXTBOX and when that textbox CHANGED event occurs mess with the radio buttons and visa-versa.
Does that seem too crazy?
Re: [2008] Mixing BOUND controls with non-BOUND controls
Handling the CurrentChanged event of the BindingSource (not BindingNavigator) is exactly what you should do.
An alternative would be to create your own UserControl containing these RadioButtons. You could then bind your data to that UserControl and handle the logic yourself internally.
1 Attachment(s)
Re: [2008] Mixing BOUND controls with non-BOUND controls
Sorry - I did mean the binding source - not the BN...
But I gotta tell you - we are very, very happy with this trick.
We have the 4 radio buttons - which cannot be bound to a single field.
But - you can bind a textbox to that field - PHONEFLAG. And by simply tracking this TEXTCHANGED event the buttons always match the "textbox"
Code:
Private Sub PhoneFlag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhoneFlag.TextChanged
Select Case Me.PhoneFlag.Text
Case "H"
Me.PrimaryHome.Checked = True
Case "O"
Me.PrimaryOffice.Checked = True
Case "C"
Me.PrimaryCell.Checked = True
Case "OT"
Me.PrimaryOther.Checked = True
End Select
End Sub
Then changing a radio button only needs to do this (if you have the .Tag property of each radio button set to the "value" you want in the bound-textbox)
Code:
Private Sub PrimaryHome_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles PrimaryHome.CheckedChanged, PrimaryOffice.CheckedChanged _
, PrimaryCell.CheckedChanged, PrimaryOther.CheckedChanged
If TryCast(sender, RadioButton).Checked Then
Me.PhoneFlag.Text = TryCast(sender, RadioButton).Tag.ToString
End If
End Sub
PHONEFLAG is bound properly to the database - changes to the radio button are instantly reflected in the textbox. And also reflected on other forms that are bound to this data.
Very effortless.
Then when we are happy all is working we just make the TEXTBOX not visible.
Re: [2008] Mixing BOUND controls with non-BOUND controls
I still think using a UserControl containing your RadioButtons and keeping all that logic internal would be a better idea.
Re: [2008] Mixing BOUND controls with non-BOUND controls
I like the idea of hiding the logic - when I get a moment I'll try that path and post back with what is different.
Thanks!
Re: [2008] Mixing BOUND controls with non-BOUND controls
This is cleaner logic - it turn off all buttons when the textbox has a blank (non-matching) value
Code:
Private Sub PhoneFlag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhoneFlag.TextChanged
Me.PrimaryHome.Checked = Me.PhoneFlag.Text = Me.PrimaryHome.Tag.ToString
Me.PrimaryOffice.Checked = Me.PhoneFlag.Text = Me.PrimaryOffice.Tag.ToString
Me.PrimaryCell.Checked = Me.PhoneFlag.Text = Me.PrimaryCell.Tag.ToString
Me.PrimaryOther.Checked = Me.PhoneFlag.Text = Me.PrimaryOther.Tag.ToString
End Sub