CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Binding option buttons to data



    I have a form with bound controls to a data source.

    The text and list controls work ok but I can't seem to

    get the option button to update when I change records.

    What it the best way to update the option buttons and

    check marks when changing to a new record.

    Thanks for any replies.

  2. #2
    Join Date
    Apr 1999
    Location
    Rotterdam, Netherlands
    Posts
    278

    Re: Binding option buttons to data



    As far as I know, you cannot bound datacontrols to option buttons.

    You could write one your own (with VB 5 / 6).

    Or write a wrapper function, which reads the datafield, and depending on that value set an option-button on or off.


    Hope it helps


    Crazy D

  3. #3
    Join Date
    Apr 1999
    Posts
    16

    Re: Binding option buttons to data



    Tim-


    The best way I have found is to bind the field to a HIDDEN text box, and use events to tie it to a checkbox.


    For example:



    '' Triggered by user action

    Private Sub Check1_Click()

    '' Use 1 for checked, 0 for unchecked

    If (Check1.Value = vbChecked) Then

    Text1.Text = "1"

    Else

    Text1.Text = "0"

    End If

    End Sub


    '' Triggered by record refresh

    Private Sub Text1_Change()

    If (Text1.Text = "1") Then

    Check1.Value = vbChecked

    Else

    Check1.Value = vbUnchecked

    End If

    End Sub




    You may think that this would cause an endless loop, but VB stops firing events if the data doesn't change.


    This also allows you to make a "Y/N" (character) field into a checkbox.


    -Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured