我正在使用 ctype 从字符串转换为文本框。这些文本框存在于表单上。转换后,我得到数据并显示在文本框中。我第一次打开表格一切顺利。退出并再次运行表单后,ctype 会抛出错误“NullReferenceException”。在 debug 上,我发现一个 ctype 没有返回任何内容。为什么会这样?
代码如下:
Private Sub CompanyId_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CompanyId.SelectedIndexChanged, FundType.SelectedIndexChanged, FundGroup.SelectedIndexChanged, Currency.SelectedIndexChanged, Frequency.SelectedIndexChanged, MngmtFees.SelectedIndexChanged
If INLOAD = True Then Exit Sub
Dim cmb As ComboBox
cmb = DirectCast(sender, ComboBox)
Dim TXTNAME As String
TXTNAME = cmb.Name & "_Name"
Dim NEWTEXT As TextBox = CType(Me.Controls(TXTNAME), TextBox)
*****If NEWTEXT Is Nothing Then MsgBox("hOW TO???")*****
If cmb.Name = "CompanyId" Then NEWTEXT.Text = dc.Tables("Company").Rows(cmb.FindStringExact(cmb.Text)).Item(1).ToString
If InStr(cmb.Name, "Fees") > 0 Then NEWTEXT.Text = dc.Tables("Fees").Rows(cmb.FindStringExact(cmb.Text)).Item(1).ToString
If NEWTEXT.Text = "" Then NEWTEXT.Text = dc.Tables(cmb.Name).Rows(cmb.FindStringExact(cmb.Text)).Item(1).ToString()