[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Find checked value in ArrayList

Hello all !

How can I determine if  a checkbox has been checked in an arraylist in VB.NET.

Thanks.

Deb
0
DMV
Asked:
DMV
  • 3
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Like this?....

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private cbs As New ArrayList

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim c As Control

        For Each c In Me.Controls
            If TypeOf c Is CheckBox Then
                cbs.Add(c)
            End If
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cb As CheckBox

        For Each cb In cbs
            If cb.Checked Then
                MsgBox(cb.Name & " checked")
            End If
        Next
    End Sub

End Class

0
 
DMVAuthor Commented:
Thanks much!
0
 
DMVAuthor Commented:
one more thing....

How do I add all the values in cbs to another arraylist (cbs2),  if the checkbox is checked?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private cbs As New ArrayList
    Private cbs2 As New ArrayList

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim c As Control

        For Each c In Me.Controls
            If TypeOf c Is CheckBox Then
                cbs.Add(c)
            End If
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cb As CheckBox

        cbs2.Clear()
        For Each cb In cbs
            If cb.Checked Then
                cbs2.Add(cb.Text)
            End If
        Next

        Dim s As String
        For Each s In cbs2
            Debug.WriteLine(s)
        Next
    End Sub

End Class

0
 
DMVAuthor Commented:
Thanks Mike -- please view my follow-up to this question for additional points:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21400313.html

Deborah
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now