Radio Button Events

I am using VB.NETs Radio Buttons on my data form. These two radio buttons will reflect what's in a bound textbox that displays "Male" or "Female". I will eventually hide this textbox. I wish to have radio buttons with a selection of Male or Female. I put the following code in both the BindingNavigatorMoveNextItem.Click and BindingNavigatorMovePreviousItem.Click Events

Select Case txtMaleOrFemale.Text
Case "Male"
rbMale.Select()
Case "Female"
rbFemale.Select()
End Select

It seems to read this code before actually moving to the next recod thereby getting results that seem to be the previouse records data. I know I need to put this in a sub becuse I will also have to update at Form_Load as well. I think that I have the wrong events for this code.

I am not new at VB just unfamilar with VB.NETs Events and some Methos and Properties.


Any example you may have will be greatly appretiated.

Ben.Curtis61@coxDOTnet

Comments

  • [b][red]This message was edited by jbassmanp at 2006-6-17 16:59:0[/red][/b][hr]
    [b][red]This message was edited by jbassmanp at 2006-6-17 16:54:35[/red][/b][hr]
    [b][red]This message was edited by jbassmanp at 2006-6-17 16:42:52[/red][/b][hr]
    : I am using VB.NETs Radio Buttons on my data form. These two radio buttons will reflect what's in a bound textbox that displays "Male" or "Female". I will eventually hide this textbox. I wish to have radio buttons with a selection of Male or Female. I put the following code in both the BindingNavigatorMoveNextItem.Click and BindingNavigatorMovePreviousItem.Click Events
    :
    : Select Case txtMaleOrFemale.Text
    : Case "Male"
    : rbMale.Select()
    : Case "Female"
    : rbFemale.Select()
    : End Select
    :
    : It seems to read this code before actually moving to the next recod thereby getting results that seem to be the previouse records data. I know I need to put this in a sub becuse I will also have to update at Form_Load as well. I think that I have the wrong events for this code.
    :
    : I am not new at VB just unfamilar with VB.NETs Events and some Methos and Properties.
    :
    :
    : Any example you may have will be greatly appretiated.
    :
    : Ben.Curtis61@coxDOTnet
    :
    :
    your code is okay just add to each Navigation event:
    BindingNavigatorMovePreviousItem,BindingNavigatorMoveNextItem,BindingNavigatorMoveLastItem and BindingNavigatorMoveFirstItem - 1. the code to make sure you have a change of position reflected there. ex. for NEXT it would be for sample DB name MALEFEMALE -
    Me.MaleFeMaleBindingSource.Position +=1
    for Previous
    Me.MaleFeMaleBindingSource.Position -=1
    for LAST
    Me.MaleFeMaleBindingSource.Position = me.MaleFeMaleBindingSource.Count -1
    for FIRST
    Me.MaleFeMaleBindingSource.Position =0

    2. Then use a call to a sub checkRB() which have your code in it should work for you.
    [code]
    Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click
    Me.MaleFeMaleBindingSource.Position = 0
    CheckRB()
    End Sub

    Private Sub CheckRB
    Select Case txtMaleOrFemale.Text
    Case "Male"
    rbMale.Select()
    Case "Female"
    rbFemale.Select()
    End Select
    End Sub
    [/code]








  • Thank you for the reply. This seems to work just like it is supposed to. Only thing is, now when I add a record, it gets into the DB table just fine, but the NEXT and PREVIOUS act like the FIRST and LAST buttons. I have three test records and it seems to skip ove rec#2. I can input this record in the navicator and access that recod. Below is my current code. I clipped out the parts of the Sub signature to save space.

    Public Class frmStudentInfo

    Private Sub StudentInfoBindingNavigatorSaveItem_Click() Handles

    StudentInfoBindingNavigatorSaveItem.Click

    Me.Validate()
    Me.StudentInfoBindingSource.EndEdit()
    Me.StudentInfoTableAdapter.Update(Me.DsStudentInfo.StudentInfo)

    End Sub

    Private Sub frmStudentInfo_Load() Handles MyBase.Load

    Me.StudentInfoTableAdapter.Fill(Me.DsStudentInfo.StudentInfo)
    Me.StudentInfoBindingSource.Position = 0

    'Set to false after testing.
    Me.txtMaleOrFemale.Visible = True
    Me.txtMarriedOrDivorce.Visible = True

    CheckedRB()

    End Sub


    Private Sub BindingNavigatorMoveNextItem_Click() Handles

    BindingNavigatorMoveNextItem.Click
    '
    Me.StudentInfoBindingSource.Position += 1
    CheckedRB()

    End Sub

    Private Sub BindingNavigatorMovePreviousItem_Click() Handles

    BindingNavigatorMovePreviousItem.Click

    Me.StudentInfoBindingSource.Position -= 1
    CheckedRB()

    End Sub

    Private Sub BindingNavigatorMoveLastItem_Click() Handles

    BindingNavigatorMoveLastItem.Click

    Me.StudentInfoBindingSource.Position =

    Me.StudentInfoBindingSource.Count - 1
    CheckedRB()

    End Sub

    Private Sub BindingNavigatorMoveFirstItem_Click() Handles

    BindingNavigatorMoveFirstItem.Click

    Me.StudentInfoBindingSource.Position = 0
    CheckedRB()

    End Sub

    Private Sub rbMale_CheckedChanged()

    Me.txtMaleOrFemale.Text = "Male"

    End Sub

    Private Sub rbFemale_CheckedChanged()

    Me.txtMaleOrFemale.Text = "Female"

    End Sub

    Private Sub rbMarried_CheckedChanged() Handles

    rbMarried.CheckedChanged

    Me.txtMarriedOrDivorce.Text = "Married"

    End Sub

    Private Sub rbDivorced_CheckedChanged() Handles

    rbDivorced.CheckedChanged

    Me.txtMarriedOrDivorce.Text = "Divorce"

    End Sub


    Private Sub rbMale_CheckedChanged_1() Handles rbMale.CheckedChanged

    Me.txtMaleOrFemale.Text = "Male"

    End Sub

    Private Sub rbFemale_CheckedChanged_1() Handles

    rbFemale.CheckedChanged

    Me.txtMaleOrFemale.Text = "Female"

    End Sub

    Private Sub CheckedRB()

    Select Case txtMaleOrFemale.Text
    Case "Male"
    rbMale.Select()
    Case "Female"
    rbFemale.Select()
    End Select

    Select Case txtMarriedOrDivorce.Text
    Case "Married"
    rbMarried.Select()
    Case "Divorce"
    rbDivorced.Select()
    End Select

    End Sub

    End Class


    Why is this not going through the navigations properly? If I comment out the Position statements (one .Count Statement) the navigation works fine, but of course, the Radio buttons don't work properly.
    *Also, I had to utilize two GroupBoxes since I had two sets of Radio buttonsThank you for helping me.

  • : Thank you for the reply. This seems to work just like it is supposed to. Only thing is, now when I add a record, it gets into the DB table just fine, but the NEXT and PREVIOUS act like the FIRST and LAST buttons. I have three test records and it seems to skip ove rec#2. I can input this record in the navicator and access that recod. Below is my current code. I clipped out the parts of the Sub signature to save space.
    :
    : Public Class frmStudentInfo
    :
    : Private Sub StudentInfoBindingNavigatorSaveItem_Click() Handles
    :
    : StudentInfoBindingNavigatorSaveItem.Click
    :
    : Me.Validate()
    : Me.StudentInfoBindingSource.EndEdit()
    : Me.StudentInfoTableAdapter.Update(Me.DsStudentInfo.StudentInfo)
    :
    : End Sub
    :
    : Private Sub frmStudentInfo_Load() Handles MyBase.Load
    :
    : Me.StudentInfoTableAdapter.Fill(Me.DsStudentInfo.StudentInfo)
    : Me.StudentInfoBindingSource.Position = 0
    :
    : 'Set to false after testing.
    : Me.txtMaleOrFemale.Visible = True
    : Me.txtMarriedOrDivorce.Visible = True
    :
    : CheckedRB()
    :
    : End Sub
    :
    :
    : Private Sub BindingNavigatorMoveNextItem_Click() Handles
    :
    : BindingNavigatorMoveNextItem.Click
    : '
    : Me.StudentInfoBindingSource.Position += 1
    : CheckedRB()
    :
    : End Sub
    :
    : Private Sub BindingNavigatorMovePreviousItem_Click() Handles
    :
    : BindingNavigatorMovePreviousItem.Click
    :
    : Me.StudentInfoBindingSource.Position -= 1
    : CheckedRB()
    :
    : End Sub
    :
    : Private Sub BindingNavigatorMoveLastItem_Click() Handles
    :
    : BindingNavigatorMoveLastItem.Click
    :
    : Me.StudentInfoBindingSource.Position =
    :
    : Me.StudentInfoBindingSource.Count - 1
    : CheckedRB()
    :
    : End Sub
    :
    : Private Sub BindingNavigatorMoveFirstItem_Click() Handles
    :
    : BindingNavigatorMoveFirstItem.Click
    :
    : Me.StudentInfoBindingSource.Position = 0
    : CheckedRB()
    :
    : End Sub
    :
    : Private Sub rbMale_CheckedChanged()
    :
    : Me.txtMaleOrFemale.Text = "Male"
    :
    : End Sub
    :
    : Private Sub rbFemale_CheckedChanged()
    :
    : Me.txtMaleOrFemale.Text = "Female"
    :
    : End Sub
    :
    : Private Sub rbMarried_CheckedChanged() Handles
    :
    : rbMarried.CheckedChanged
    :
    : Me.txtMarriedOrDivorce.Text = "Married"
    :
    : End Sub
    :
    : Private Sub rbDivorced_CheckedChanged() Handles
    :
    : rbDivorced.CheckedChanged
    :
    : Me.txtMarriedOrDivorce.Text = "Divorce"
    :
    : End Sub
    :
    :
    : Private Sub rbMale_CheckedChanged_1() Handles rbMale.CheckedChanged
    :
    : Me.txtMaleOrFemale.Text = "Male"
    :
    : End Sub
    :
    : Private Sub rbFemale_CheckedChanged_1() Handles
    :
    : rbFemale.CheckedChanged
    :
    : Me.txtMaleOrFemale.Text = "Female"
    :
    : End Sub
    :
    : Private Sub CheckedRB()
    :
    : Select Case txtMaleOrFemale.Text
    : Case "Male"
    : rbMale.Select()
    : Case "Female"
    : rbFemale.Select()
    : End Select
    :
    : Select Case txtMarriedOrDivorce.Text
    : Case "Married"
    : rbMarried.Select()
    : Case "Divorce"
    : rbDivorced.Select()
    : End Select
    :
    : End Sub
    :
    : End Class
    :
    :
    : Why is this not going through the navigations properly? If I comment out the Position statements (one .Count Statement) the navigation works fine, but of course, the Radio buttons don't work properly.
    : *Also, I had to utilize two GroupBoxes since I had two sets of Radio buttonsThank you for helping me.
    :
    :
    The check_changed subs are not needed from what I can see (Unless you use this to change the status of the student married or sex info using the RadioButtons). Just use the Navigation Events and proper coding for position change followed by your call to the CheckRB sub routine. All should be fine. I included the code for each position change again make sure it is correct and if you have to break the CheckRB sub into two different ones, test it to see if one check works then add the other or create another sub for test for married check like a CheckMarriedRB... Try this... I do this kind of stuff all the time works for me.... Good Coding...
    [code]
    Private Sub BindingNavigatorMoveFirstItem_Click....BindingNavigatorMoveFirstItem.Click
    Me.StudentInfoBindingSource.Position = 0
    CheckRB()
    End Sub
    Private Sub BindingNavigatorMoveLastItem_Click....BindingNavigatorMoveLastItem.Click
    Me.StudentInfoBindingSource.Position = Me.StudentInfoBindingSource.Count -1
    CheckRB()
    End Sub
    Private Sub BindingNavigatorMoveNextItem_Click....BindingNavigatorMoveNextItem.Click
    Me.StudentInfoBindingSource.Position += 1
    CheckRB()
    End Sub
    Private Sub BindingNavigatorMovePreviousItem_Click....BindingNavigatorMovePreviousItem.Click
    Me.StudentInfoBindingSource.Position -= 1
    CheckRB()
    End Sub

    [/code]



  • Thank you for responding. I am sorry I did not respond quicker.
    I found the solution to my Radio Buttons behavior. I did not need the Potition or Count methods you gave for each binding source Navigations. I put my CheckRB subs in the RefreshItems event like so:

    Private Sub StudentInfoBindingNavigator_RefreshItems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentInfoBindingNavigator.RefreshItems

    CheckedMaleOrFemaleRB()
    CheckedMarriedOrDivorceRB()
    CheckTextBoxes()

    End Sub

    It worked the way I wanted it to. I think the reason that I do not need those methods is that the designer stubs that code in already.

    Thanks again. Without this interaction it would have taken me longer to come up with what worked.

    Bar Jabba

  • : Thank you for responding. I am sorry I did not respond quicker.
    : I found the solution to my Radio Buttons behavior. I did not need the Potition or Count methods you gave for each binding source Navigations. I put my CheckRB subs in the RefreshItems event like so:
    :
    : Private Sub StudentInfoBindingNavigator_RefreshItems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentInfoBindingNavigator.RefreshItems
    :
    : CheckedMaleOrFemaleRB()
    : CheckedMarriedOrDivorceRB()
    : CheckTextBoxes()
    :
    : End Sub
    :
    : It worked the way I wanted it to. I think the reason that I do not need those methods is that the designer stubs that code in already.
    :
    : Thanks again. Without this interaction it would have taken me longer to come up with what worked.
    :
    : Bar Jabba
    :
    Glad to hear you solved it I assumed you needed the individual navigation events for other reasons since you listed them separately. The separations are good if you do something different on each one event. Good Luck


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories