JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Setting a Checkbox's State

Your new program, SuperSandwichesToGoRightNow, is just about ready, but there's one hitch. You use checkboxes to indicate what items are in a sandwich (Cheese, Lettuce, Tomato, and more) to let the user custom-build their sandwiches, but you also have a number of specialty sandwiches with preset ingredients. When the user selects one of those already-built sandwiches, how do you set the ingredients checkboxes to show what's in them?

You can set a checkbox's state by setting its Checked property to True or False, as in this code:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    CheckBox1.Checked = True
End Sub

How can you make a checkbox appear checked when your program first starts? Just set its Checked property to True at design time.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor