我在运行时生成的组框中更改运行时生成的复选框名称时遇到问题。我正在使用多个组框,然后获取数据库中的所有行并为它们创建复选框。复选框名称如下""chkClass" & intGroupBoxNumber & intCurrentRow"。删除组框后,我会重新编号所有当前的组框,并希望复选框名称也更改为新的组框编号,如果这有意义的话。我的代码如下:
strControlName = "grpGroup" & strIBResult
Try
intGroupBoxOldYLocation = Me.Controls(strControlName).Location
Me.Controls(strControlName).Dispose()
MessageBox.Show("Deleted: " & strControlName)
intRenameGroup = strIBResult + 1
Try
strControlName = "grpGroup" & intRenameGroup
strControlNewName = "grpGroup" & intRenameGroup - 1
Me.Controls(strControlName).Location = intGroupBoxOldYLocation
Me.Controls(strControlName).Text = "Group " & intRenameGroup - 1
Me.Controls(strControlName).Name = strControlNewName
MessageBox.Show("Changed: " & strControlName & " to: " & strControlNewName)
Do While intCurrentClassRow < intTotalClassRows
strCheckBoxOldName = "chkClass" & intRenameGroup & intCurrentClassRow
strCheckBoxNewName = "chkClass" & intRenameGroup - 1 & intCurrentClassRow
MessageBox.Show("Renaming: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName
intCurrentClassRow += 1
MessageBox.Show("Renamed: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
Loop
intCurrentClassRow = 0
intRenameGroup += 1
intGroupBoxNewYIncrement = intGroupBoxOldYLocation.Y + Me.Controls(strControlNewName).Height + 50
Do
strControlName = "grpGroup" & intRenameGroup
strControlNewName = "grpGroup" & intRenameGroup - 1
Me.Controls(strControlName).Location = New Point(intCurrentXPosition, intGroupBoxNewYIncrement)
Me.Controls(strControlName).Text = "Group " & intRenameGroup - 1
Me.Controls(strControlName).Name = strControlNewName
Do While intCurrentClassRow < intTotalClassRows
strCheckBoxOldName = "chkClass" & intRenameGroup & intCurrentClassRow
strCheckBoxNewName = "chkClass" & intRenameGroup - 1 & intCurrentClassRow
Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName
intCurrentClassRow += 1
MessageBox.Show("Renamed: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
Loop
intCurrentClassRow = 0
intRenameGroup += 1
intGroupBoxNewYIncrement = intGroupBoxNewYIncrement + Me.Controls(strControlNewName).Height + 50
Loop
Catch ex As Exception
MessageBox.Show("Control: " & strControlName & " does not exist")
MessageBox.Show(ErrorToString)
End Try
Catch ex As Exception
'MessageBox.Show("Control: " & strControlName & " never existed")
MessageBox.Show("Please enter a valid group number to delete.", "Invalid Entry")
Exit Sub
End Try
我很确定我的麻烦现在存在于 Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName
错误如下:“对象引用未设置为对象的实例”
是否有不同的方法来引用该运行时生成的组框?
谢谢。对不起,如果这令人困惑!