这是一篇旧帖子,但我遇到了“Option Strict On 不允许后期绑定”错误。也许另一个答案会帮助别人。当您尝试将 SF6StdData 绑定源中的数据转换为字符串时,可能会出现问题。您可以通过定义具有所需类型的局部变量,然后使用 Ctype 将数据提取到正确的类型来解决该问题。这是我如何解决类似问题的示例。
这段代码给了我后期绑定错误:
Friend Function CountNumCheckedInGroupbox(ByVal gbox As GroupBox, ByRef nameschecked() As String) As Integer
Dim numchecked As Integer = 0
For Each ctrl In gbox.Controls
If TypeOf ctrl Is CheckBox Then
If ctrl.Checked = True Then
nameschecked(numchecked) = ctrl.Text
numchecked += 1
End If
End If
Next
Return numchecked
End Function
后期绑定错误发生在我引用“ctrl.Checked”和“ctrl.Text”的地方
我没有直接引用“ctrl”,而是定义了一个类型为 Checkbox 的变量 cbox。然后我将“ctrl”中的信息提取到cbox中。现在代码不显示后期绑定错误:
Friend Function CountNumCheckedInGroupbox(ByVal gbox As GroupBox, ByRef nameschecked() As String) As Integer
Dim numchecked As Integer = 0
Dim cbox As CheckBox
For Each ctrl In gbox.Controls
If TypeOf ctrl Is CheckBox Then
cbox = CType(ctrl, CheckBox)
If cbox.Checked = True Then
nameschecked(numchecked) = cbox.Text
numchecked += 1
End If
End If
Next
Return numchecked
End Function