问题描述
我正在尝试使用TextChanged事件来初始化第二个文本框.第二个文本框还取决于第三个文本框的值.更改BindingSourcePosition时,这些值会更改.
前任.
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
这让我有点恼火,因为我不能依赖表单上字段更新的顺序.即使使用TabOrder似乎也没有改变表单的更新顺序.还是我错过了什么?
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.
推荐答案
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
这篇关于BindingSource PositionChanged和TextChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!