Visual studio 在表单中清除数据。Visual Basic
我想清除此表格中的数据。 你能告诉我这个代码有什么问题吗Visual studio 在表单中清除数据。Visual Basic,visual-studio,controls,Visual Studio,Controls,我想清除此表格中的数据。 你能告诉我这个代码有什么问题吗 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim ctrl As Control For Each ctrl In Me.Controls If TypeOf ctrl Is RadioButton Then
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is RadioButton Then
RadioButton2.Checked = False
End If
Next
End Sub
试试这个:
If TypeOf ctrl Is RadioButton Then
ctrl.Checked = False
End If
在您当前的代码中,您正在遍历所有控件,但只更新RadioButton2的Checked属性。以下代码对我有效:
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is RadioButton Then
'reset the checked property to ALL your radioButtons
DirectCast(ctrl, RadioButton).Checked = False
End If
Next
您将在表单中循环所有控件。这不起作用。这段看似正常的代码也不起作用。ElseIf TypeOf ctrl是RadioButton,然后是CType(ctrl,RadioButton)。选中=False结束,如果