Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Loading
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 3: User Interface Design: Visual Basic Controls and Events
Last change: February 13 2016 18:47:26.
<<PreviousNext>>

The CheckedChanged Event: Radio Buttons and Check Boxes

When the user changes a selection among a group of radio buttons or checks on (or off) a check box, the CheckedChanged event is triggered. You can place code in this event if a certain response is expected. For example, assume in a mailing label printing application, the user has a choice of printing all members or only those in the zip code areas selected from a list box named lstZipCode. The user indicates the choice by checking on a check box named chkSelectionOnly with a text, “Print selected list only.” It is obvious that the list box is needed only when the check box is checked on; otherwise, the list box should be disabled. At design time, the checkbox’s Checked property is set to True for consistency with the list box’s Enabled property. At runtime, your code should respond to the changes in the checkbox’s Checked property. The code should be placed in the CheckedChanged event as follows:

Private Sub chkSelectionOnly_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectionOnly.CheckedChanged lstZipCode.Enabled = chkSelectionOnly.Checked End Sub

In the event procedure, the value of the checkbox’s Checked property is assigned to the Enabled property of the list box. This in effect enables or disables the list box, depending on the checked state of the check box. When the checkbox is checked on, its Checked property is set to True and is assigned to the Enabled property of the list box, thus enabling the list box. By the same token, when the check box is checked off, it will cause the list box to be disabled.

Last change: February 13 2016 18:47:27.
<<PreviousNext>>