Skip to Content
author's profile photo Former Member
Former Member

Option Button

Good Afternoon

Experts:

I have a very basic need that I cannot seem to accomplish after reviewing the samples and help files regarding Option Buttons.

I need 2 options buttons NOT grouped together. They need to toggle on/off independent of eachother. Here is what I have so far:

'Rework

PREQItem = PREQForm.Items.Add("btnReWork", it_OPTION_BUTTON)

PREQItem.Height = 14

PREQItem.Left = 225

PREQItem.Top = 240

PREQItem.Width = 20

PREQOptBtn2 = PREQItem.Specific

PREQOptBtn2.DataBind.SetBound(True, "", "U_Rework")

PREQOptBtn2.ValOn = "Y"

PREQOptBtn2.ValOff = "N"

'Hot

PREQItem = PREQForm.Items.Add("btnHot", it_OPTION_BUTTON)

PREQItem.Height = 14

PREQItem.Left = 175

PREQItem.Top = 240

PREQItem.Width = 20

PREQOptBtn = PREQItem.Specific

PREQOptBtn.DataBind.SetBound(True, "", "U_Hot")

PREQOptBtn.ValOn = "Y"

PREQOptBtn.ValOff = "N"

If PREQOptBtn.Selected = False Then

PREQForm.DataSources.UserDataSources.Item("U_HOT").ValueEx = "Y"

PREQOptBtn.Selected = True

Else

PREQForm.DataSources.UserDataSources.Item("U_HOT").ValueEx = "N"

PREQOptBtn.Selected = False

End If

Seems logical but of course it does not work. Simple...If the button is not selected, set Datasource to Y and select button Else the button is selected so set Datasource to N and deselect button.

Can anyone help with how I need ot achieve my results?

Thanks,

EJD

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 01, 2007 at 02:24 AM

    Options buttons aren't really intended for this - checkboxes would be the normal choice for independant on/off selection fields.

    An option buttons Selected property only ever gets set to True when you click on it - clicking on it again won't set it to false.

    It is still possible to get the effect you want though. Simply use a variable to record the current state of the userdatasource, and put custom code into the item pressed event to toggle the user data source to the opposite value each time the option button is clicked. For example:-

    If pVal.EventType = et_ITEM_PRESSED And pVal.BeforeAction = False Then
        
        Select Case pVal.ItemUID
        
            Case "btnHot"
                If mstrHot = "Y" Then
                    msboUDS("U_HOT").ValueEx = "N"
                Else
                    msboUDS("U_HOT").ValueEx = "Y"
                End If
                mstrHot = msboUDS("U_HOT").ValueEx
                
            Case "btnReWork"
                If mstrRework = "Y" Then
                    msboUDS("U_Rework").ValueEx = "N"
                Else
                    msboUDS("U_Rework").ValueEx = "Y"
                End If
                mstrRework = msboUDS("U_Rework").ValueEx
                
        End Select
        
    End If
    

    John.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.