Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you have probably noticed, there may be a few different places where you need to do this. To reuse a piece of functionality, create a new method that does that job. Double-click the form, and place this just before the End Class:</p> <pre><code>''' &lt;summary&gt;Update each of the CheckBoxes that in the same GroupBox&lt;/summary&gt; ''' &lt;param name="sender"&gt;The CheckBox that was clicked.&lt;/param&gt; ''' &lt;param name="e"&gt;&lt;/param&gt; ''' &lt;remarks&gt;It is assumed that only checkboxed that live in a GroupBox will use this method.&lt;/remarks&gt; Public Sub UpdateCheckBoxState(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Get the group box that the clicked checkbox lives in Dim parentGroupBox As System.Windows.Forms.GroupBox = DirectCast(DirectCast(sender, System.Windows.Forms.CheckBox).Parent, System.Windows.Forms.GroupBox) For Each ctrl As System.Windows.Forms.Control In parentGroupBox.Controls 'Only process the checkboxes (in case there's other stuff in the GroupBox as well) If TypeOf ctrl Is System.Windows.Forms.CheckBox Then 'This control is a checkbox. Let's remember that to make it easier. Dim chkBox As System.Windows.Forms.CheckBox = DirectCast(ctrl, System.Windows.Forms.CheckBox) If chkBox.CheckState = 1 Then chkBox.Text = "Deselect All" Else chkBox.Text = "Select All" End If End If ' - is CheckBox Next ctrl End Sub </code></pre> <p>Now you have a method that will do what you want, you need to connect it to each CheckBox that you want to manage. Do this by adding the following code in The Form_Load event:</p> <pre><code> AddHandler CheckBox1.CheckedChanged, AddressOf UpdateCheckBoxState AddHandler CheckBox2.CheckedChanged, AddressOf UpdateCheckBoxState ... </code></pre> <p>So now the same method will handle the ClickChanged method of all of your connected checkboxes.</p> <p>You can also update the checkBoxes in addition to when the user clicks it by calling the Method <code>UpdateCheckBoxState(</code><em>CheckBoxThatYouWantToProgramaticallyUpdate</em><code>, Nothing)</code> perhaps in Form_Load, or elsewhere.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload