清除表格中的数据。 Visual Basic

时间:2013-09-22 11:44:24

标签: visual-studio controls clear

我想清除此表单中的数据。 你能告诉我这段代码有什么问题吗?

 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

2 个答案:

答案 0 :(得分:0)

试试这个:

If TypeOf ctrl Is RadioButton Then
     ctrl.Checked = False
End If

在当前代码中,您循环遍历所有控件,但只更新RadioButton2的Checked属性。

答案 1 :(得分:0)

以下代码适用于我:

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

您将循环播放表单中的所有控件。

相关问题