DMV
asked on
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
How can I determine if a checkbox has been checked in an arraylist in VB.NET.
Thanks.
Deb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
one more thing....
How do I add all the values in cbs to another arraylist (cbs2), if the checkbox is checked?
How do I add all the values in cbs to another arraylist (cbs2), if the checkbox is checked?
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
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
ASKER
Thanks Mike -- please view my follow-up to this question for additional points:
https://www.experts-exchange.com/questions/21400313/Redux-Arraylists-and-checkboxes.html
Deborah
https://www.experts-exchange.com/questions/21400313/Redux-Arraylists-and-checkboxes.html
Deborah
ASKER