DataBinding a RadioButton group

  • Thread starter Thread starter Srikanth
  • Start date Start date
S

Srikanth

Hi,
I have two RadioButtons in a GroupBox. I want to databind these
radiobuttons with a value (if '0', one radiobutton is checked else another)
of a column in a DataTable.

Iam not able to figure out how to do this. Please someone help me.

Regards,
Srikanth.
 
You cannot. Think about this... If I bind oth radio buttons to the same field and assuming the value is true BOTH of the controls cannot be true

RadioButton1.DataBindings.Add("Checked", ds, "Cust.Contract")
RadioButton2.DataBindings.Add("Checked", ds, "Cust.Contract")

then what is going to happen is that Radio button 2 is going to be set to the true value and clear 1 even though 1 should also be true.

What you need to do is bind another control (Like a Textbox) then trap the Change events and set the Radio buttons accordingly, and trap the Radio button events to set the value
of the text box that is bound.

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
 
Scott has the correct answer. I have several on my form. In each case, I
set the value of a textbox and that textbox is bound to my data.

On the opening of the form I set the values of the checkboxes.

If Not HasLoaded Then Exit Sub
If Me.txtLoanLease.Text = "Loan" Then
Me.chkLoan.Checked = True
Me.chkLease.Checked = False
ElseIf Me.txtLoanLease.Text = "Lease" Then
Me.chkLoan.Checked = False
Me.chkLease.Checked = True
End If
 
Back
Top