Results 1 to 6 of 6

Thread: [2008] Mixing BOUND controls with non-BOUND controls

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    [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?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.
    Attached Images Attached Images  
    Last edited by szlamany; Jan 26th, 2009 at 08:43 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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