Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I'm trying to use the TextChanged event to initialize a second textbox. The second textbox also depends on the value of a third textbox value. These values change when changing the BindingSourcePosition.
 
Ex.
 
Private Sub StudentScheduleBindingSource_Position(ByVal sender As System.Object, _ 
            ByVal e As System.EventArgs) _
            Handles StudentScheduleBindingSource.PositionChanged
        
            'Some code.
End Sub
 
'The above event changes the textbox data and triggers the TextChanged event below

Private Sub TalkTextBox_TextChanged(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) _
            Handles T1TextBox.TextChanged, T2TextBox.TextChanged, _
                    T3TextBox.TextChanged, T1aTextBox.TextChanged, _
                    T2aTextBox.TextChanged, T3aTextBox.TextChanged, _
                    T3bTextBox.TextChanged   
  Dim tb as TextBox = sender  'For this example assume T1TextBox is sender
  If tb.Text <> "" then
     id = FindInArray(studentNames, tb.Text) 'Find the student in the array
     cnsl = AllStudents(id, byCounsel) ' Get the counsel point they are working on
  End If
 
  ' This is where the problem starts
  ' tmsReview textbox stil has the old value in it and hasn't updated yet.
  ' schDateTextBox also has to old value (last week) and hasn't updated yet.
  ' Therefore T1Counsel.Text will not be correct.
  If tmsReview.Text = "Review" then 
       T1Counsel.Text = "R"
  Else
       T1Counsel.Text = cnsl
  End if
 
  'This code doesn't work either. Because it too is a week off.
  'Assume schDateTextBox is sender and has been added to Handles list
  If schDateTextBox.Text = reviewWeek then 
       T1Counsel.Text = "R"
  Else
       T1Counsel.Text = cnsl
  End if
 
End Sub
 
'Another attempt is to capture the Date change and compare it with the Review data
'This doesn't work because the tmsReviewTextBox still may not have updated yet _
'  and the T1CounselTextBox will still be wrong. When the T1TextBox.TextChanged _
'  is triggered it may overwrite the T1CounselTextBox
Private Sub SchDateTextBox_TextChanged(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles SchDateTextBox.TextChanged
  If tmsReview.Text = "Review" then 
       T1Counsel.Text = "R"
  Else
       T1Counsel.Text = cnsl
  End if
 
 

'This is the only way I can get it to work.
'Create an array containing all ReviewDates and search for them _
'  each time the StudentScheduleBindingSource_Position event is triggered
Private Sub SchDateTextBox_TextChanged(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles SchDateTextBox.TextChanged
    If FindInArray(tmsReviewDates, CDate(SchDateTextBox.Text)) >= 0 Then
       T1CounselTextBox.Text = "R"
    End If
End Sub
 
 
This is a little irritating to me because I can't rely on the order of updating fields on the form. Even using the TabOrder doesn't seem to make a difference on update order for the form. Or am I missing something.
Posted 30-Sep-12 8:28am
Edited 1-Oct-12 16:38pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
       If TextBox1.Text = "Review" Then
           TextBox2.Text = ""
       Else
           TextBox3.Text = "Value"
       End If
 
   End Sub
 
This working fine, what is whole problem ?
 
Maybe you will try this ?
 
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
       If TextBox1.Text = "Review" Then
           TextBox2.Text = ""
           TextBox3.Text = "Value"
       Else
           TextBox3.Text = ""
       End If
 
   End Sub
  Permalink  
v2
Comments
Andrew Alix at 30-Sep-12 19:36pm
   
I believe you misunderstood my problem. This code works fine in a form. But when the BindingNavigator changes position, it also triggers a .TextChanged event when the form updates to the new row. The problems is that, of course, not all textboxes update at the same time. And even the bindingSource.positionChanged event isn't triggered before other textboxes update.
This means that I cannot rely on the value of a textbox when changing another textbox.
 
For example, Textbox1 has a name. Textbox2 has a number (counsel point) which depends on Textbox1 having the correct name. TextBox1 and Textbox3 are updated when the BindingNavigator Position button is clicked on. Unforetunately Textbox 3 doesn't get updated before TextBox1 change event is triggered so it has "old" data in it and can't be relied on. If I use the TextChanged event on Textbox3, the data in Textbox1 may not have updated yet and is still "old".
 
Is this any clearer?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Do you try ?
 
Use the Clear method of the controls property. Call the method just before you start loading the new data.
 
.Clear
 
or
 
.Refresh - Forces the control to invalidate its client area and immediately redraw itself and any child controls.
  Permalink  
Comments
Andrew Alix at 13-Nov-12 20:50pm
   
Don't you just love how easy it is?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Do you may put here whole piece of code ?
  Permalink  
Comments
Andrew Alix at 1-Oct-12 21:38pm
   
Please see updated question with code example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 485
1 OriginalGriff 310
2 Shweta N Mishra 244
3 Mathew Soji 225
4 BillWoodruff 200
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100