radiobuttons don't function as expected on forms that have databound fields

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
check out the code below
VB.NET:
        MsgBox(ModuleUser.frmUserRegistration.txtGender.Text)
        'get gender field value for display
        If ModuleUser.frmUserRegistration.txtGender.Text = UCase("m") Then
            'check male radiobox when user is a male
            ModuleUser.frmUserRegistration.RBMale.Checked = True
            ModuleUser.frmUserRegistration.RBFemale.Checked = False
        ElseIf ModuleUser.frmUserRegistration.txtGender.Text = UCase("f") Then
            'check female radiobox when user is a female
            ModuleUser.frmUserRegistration.RBMale.Checked = False
            ModuleUser.frmUserRegistration.RBFemale.Checked = True
        Else
            'gender is not specified, leave both radioboxes empty
            ModuleUser.frmUserRegistration.RBMale.Checked = False
            ModuleUser.frmUserRegistration.RBFemale.Checked = False
        End If
the txtGender.Text is databound,
when i execute it with a record contains value "m", the messages shows "m". and the the radiobutton "RBMale" is suppose to be checked. however, it wasn't.
is it because on the frmUserRegistration, i have databound fields, which affected the radiobuttons? i tried the same code on another form which doesn't have databound fields, it workd perfectly.
can anyone help plz?
 
well, the msgbox is just used to test the code.

i bind textboxes visually in design view. all that in code is to set parameter of sqlselectcommand, clear dataset and sqldataadapter.fill(dataset).
I put for checking radios right after these code.

can u still help more plz?
 
well, it's connected to my local mssql db, i dont know how to attach it with the project together yet, but you can try this if u really keen to help me out, it is very much appreciated! :)

Design view:-------------------
1. open a new project, get 2 new forms, frm1 and frm2.
2. on frm1, put a button called btn1
3, on frm2, put 2 radioboxex, rdbMale and rdbFemale
4, on frm2, drop a sqlconnection, sqldataadapter and generate a dataset
5, on frm2, put some textboxes and set databindings with the dataset columns

Code view:---------------
1, on frm1 btn1_onClick event, code this:
VB.NET:
dim frm2 as new frm2
frm2.show()
 
'fill the databound textboxes
frm2.sqlconnection.open
frm2.sqlselectcommand.parameter(xxxx).value = yyyyy  'xxxx is any parameter name that you setup in the command, yyyy is any value that exists.
frm2.dataset.clear
frm2.sqldataadapter.fill(frm2.dataset)
frm2.sqlconnection.close
 
'do the radioboxes here, you can code anything you want here, but make sure never have both checked.
frm2.rdbMale.checked = False
frm2.rdbFemale.checked = True
Now you can run it and see what i mean. you will find that actually the radioboxes are not databound and got nothing to do with those databound textboses at all.
 
Back
Top