Results 1 to 2 of 2

Thread: How to clear a RadioButton

  1. #1
    filleke is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    4
    Reputation
    0

    How to clear a RadioButton

    Hello,

    I created a function to clear any fields in my forms but I also want to uncheck the radiobuttons in the form. I can't apparently use the rb.checked property.

    Any suggestions?

    Code:
    Public Sub ClearForms(ByVal frm As Form)
            Dim ctrl As Control
            For Each ctrl In frm.Controls
                If TypeOf ctrl Is TextBox OrElse TypeOf ctrl Is ComboBox _
               Then
                    ctrl.Text = ""
                End If
                If TypeOf ctrl Is RadioButton Then
                    ?????????
                End If
            Next
        End Sub

  2. #2
    Don Delegate is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 4.5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    140
    Reputation
    112
    Code:
    If TypeOf ctrl Is RadioButton Then
        DirectCast(control, RadioButton).Checked = False
    End If
    
    Other way is: code the initial settings you want for all controls in a method Clear (or Reset, or Init,...). Call this method from your Load event handler.
    If you need it elsewhere: just call the method again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking