VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[INFO] .NET behaves differently from VB6 if you disable a checked OptionButton control in Form_Load event handler

We have noticed a minor difference in how VB6 and .NET behave if the Form_Load event handler contains these statements:

Option1.Value = True
Option1.Enabled = False

Under VB6, the above statement cause the enabled OptionButton control with the lowest TabIndex value to become checked (i.e. Value=True), whereas under .NET the Option1 control will be checked even if it is disabled.

If your migrated code relies on the VB6 behavior, the only way to have it work correctly is emulating such a behavior, which you can do by means of the following method:

Public Sub SetCheckedOptionButton(container As Control)
   ' exit if wrong input
   If container Is Nothing Then Return
   Dim nextOptionButton As VB6OptionButton
   For Each ctrl As Control In container.Controls
      Dim tempOptionButton As VB6OptionButton = TryCast(ctrl, VB6OptionButton)
      If tempOptionButton IsNot Nothing Then
         ' verify the value
         If tempOptionButton.Checked Then
            ' the control is checked and enabled ... all ok.
            If tempOptionButton.Enabled Then Return
            ' verify the enable, one of this could became the new checked one
            If tempOptionButton.Enabled Then
               ' the first found
               If nextOptionButton Is Nothing Then
                  nextOptionButton = tempOptionButton
                  ' select the one with the minimum tabindex
                  If nextOptionButton.TabIndex > tempOptionButton.TabIndex Then
                     nextOptionButton = tempOptionButton
                  End If
               End If
            End If
         End If
      End If
   ' if we have found something... set the value
   If nextOptionButton IsNot Nothing Then nextOptionButton.Checked = True
End Sub

The SetCheckOptionButton is meant to be invoked from inside the Form_Load event handler, or immediately after you change the Enabled or Value properties of one or more OptionButton controls in a group.

Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers