How to Clear a Radio Button on Visual Basic

Techwalla may earn compensation through affiliate links in this story.
Image Credit: littlehenrabi/iStock/Getty Images

Radio buttons are a common type of graphic user interface (GUI) component that allow one item out of a list of items to be selected in a program. The buttons generally appear as a series of while circles, with the selected item filled in with a dot. In most applications, one option of the radio button set will always be selected, but it might be necessary to clear them all.


Step 1

Create a new project by selecting "New Project" from the File menu. Press "OK" or "Next" in any dialogue boxes that come up, as the default options are all we need to select. You should see a blank form. Go to the components list on the left-hand side of your screen and find the entry for the radio button.

Step 2

Drag three radio buttons onto your form and place them wherever you like. If you like, you can press the "Compile and Run" button now (it appears as a green arrow on the toolbar) and test the radio buttons. You can do this by clicking each radio button in your window to ensure that only one can be selected at any given time.


Step 3

Find the button in the "Components" list and drag it onto the form. While the button is still selected, go to the "Properties" window on the bottom right of your screen and change its text property to read: "Clear Radio Buttons."

Step 4

Double click the button. This will instantly switch you from the GUI design interface where you lay out components to the source code editor, which lets you assign programming to the components. It will also create an event function for the button. This section of code will run whenever the button is pressed by the user. By default, it will have a name like this:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click ... End Sub

However, it might look slightly different depending on your version of Visual Basic.

Step 5

Within the "Button1_Click" function, add the following code to clear all the radio boxes:

RadioButton1.Checked = False
    RadioButton2.Checked = False
    RadioButton3.Checked = False

Run your program again and select one of the radio components. When you are ready, click the "Clear" button and the radio buttons will be cleared.