Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:14:36+00:00 2026-06-14T13:14:36+00:00

I have 20 checkboxes. This is the event for the checkbox nº1 : Public

  • 0

I have 20 checkboxes.

This is the event for the checkbox nº1 :

Public Sub C1CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles C1CheckBox1.CheckedChanged
    If C1CheckBox1.Checked = True Then My.Settings.box1_selected = "Y" Else My.Settings.box1_selected = "N"
    Dim checkedpath1 = C1CheckBox1.Text
End Sub

I know I can add all the checkboxes in the "handles", but my number of checkboxes is undetermined and this is what I want to do:

(Pseudocode)

Public Sub ALL_THE_CHECKBOXES_CheckedChanged(sender As Object, e As EventArgs) Handles ALL_THE_CHECKBOXES.CheckedChanged
    If ANY_CHECKBOX.Checked = True
        My.Settings.boxNUMBER_OF_THIS_SELECTED_CHECKBOX_selected = "Y"
    Else 
        My.Settings.boxNUMBER_OF_THIS_SELECTED_CHECKBOX_selected = "N"
    End If
    Dim checkedpathNUMBER_OF_THIS_SELECTED_CHECKBOX = C1CheckBoxNUMBER_OF_THIS_SELECTED_CHECKBOX.Text
End Sub

I need to generate a event that handles an undetermined number of checkboxes,
I need to do the same action if any of the checkboxes is selected, but only in that selected checkbox.

Basically I want to remember in the settings which checkboxes was selected and which not…

UPDATE:

At form load I create ALL the form checkboxes with this code:

Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim List As Integer = 0
    Dim posy As Integer = 10

    filesystem = CreateObject("Scripting.FileSystemObject")
    ThisDir = filesystem.GetFolder(My.Settings.folderpath)

    For Each folder In ThisDir.Subfolders
        List = List + 1
        posy = posy + 20

        Dim newCheckBox As New CheckBox()
        Panel1.Controls.Add(newCheckBox)
        newCheckBox.Name = "checkbox" & List.ToString()
        newCheckBox.Text = folder.name
        newCheckBox.Location = New Point(10, posy)
    Next
End Sub

That creates a checkboxes named "checkbox1", "checkbox2", "checkbox3", etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:14:37+00:00Added an answer on June 14, 2026 at 1:14 pm

    All checkboxes are inside of another control. might be form, panel whatever. So you can cycle through these checkboxes and manually assign the eventhandler for each checkbox you find

    Revised Sample code:

    You need a setting of type StringCollection named MyCBs – or you can use whatever name you like, just make the necessary changes to the code.

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.Save()
    End Sub
    
    Private Sub AnyCB_CheckedChanged(sender As Object, e As EventArgs)
    
        Dim cb = DirectCast(sender, CheckBox)
        If cb.Checked AndAlso Not My.Settings.MyCBs.Contains(cb.Name) Then
            My.Settings.MyCBs.Add(cb.Name)
        ElseIf Not cb.Checked AndAlso My.Settings.MyCBs.Contains(cb.Name) Then
            My.Settings.MyCBs.Remove(cb.Name)
        End If
    
    End Sub
    
    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    
        If My.Settings.MyCBs Is Nothing Then My.Settings.MyCBs = New Collections.Specialized.StringCollection
    
        For Each s In My.Settings.MyCBs
            DirectCast(Me.Controls(s), CheckBox).Checked = True
        Next
    
        For Each cb In Me.Controls.OfType(Of CheckBox)()
            AddHandler cb.CheckedChanged, AddressOf AnyCB_CheckedChanged
        Next
    
    End Sub
    

    This sample saves the checked status of the checkboxes in my.settings inside a StringCollection. If a CB is checked it’s name is added to the collection, if it’s unchecked, it’s name is removed. This means on startup you can simply check which CB name is in the collection and sets its checked stats to true. Finally you use AddHandler to execute the code for any CB contained in your Form.
    Note that there’s NO error handling inside the code, which means that this is your part …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
I have some checkboxes like this: <input type=checkbox name=regions[] value=north-east />North East<br /> <input
I have ten checkboxes and Enum. I want to bind this checkboxes to Enum.
I have two checkboxes generated like this: <table> <?php foreach ($invited_members as $mem) :
He, I have this page where i have checkboxes next to every item in
I have some checkboxes bound to an array in my model. This works great,
I have this long list of checkboxes with specific labels that look something like
I have this long list of checkboxes with specific labels that look something like
I have this list of people with checkboxes next to their names. When you
I have a list of checkboxes in a table like this along with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.