Previous | Index | Next 

[INFO] VB.NET automatically sets the Checked property of the first control in a group of Option buttons

VB6 allows you to define a group of Option controls and leave the Value property of all of them set to False: when the form displays, none of the controls in the group is checked. In same circumstances, VB.NET automatically sets the Value property to True for the first Option control in the group.

You can mimic VB6 behavior under VB.NET by setting the Value property to True and then to False via code before the form becomes visible, for example inside the Form’s Load event handler:

        Private Sub Form_Load()
            ' ensure that the Option1 control is unchecked
            Option1.Value = True: Option1.Value = False
            ' …
        End Sub

This trick works but has an undesired side effect: it fires the Option control’s Click event twice. If you don’t want this event to be fired, you can call the special ResetValue method exposed by the VB6OptionButton class. You can do this by inserting a call to this method via an InsertStatement pragma:

        Private Sub Form_Load()
            '## InsertStatement Option1.ResetValue()
            ' …
        End Sub

 

Previous | Index | Next