Shubham
Shubham

Reputation: 22339

How to get Checked CheckBox tag value in Vb.Net?

I have grouped some checkbox in GroupBox1, 2, 3 respectively. Now I want to know the tag value ( I am using a TAG property to assign a some value to radio button ) of check box which is checked in either of the groupboxes.

Is there any solution besides using if then statements?

Upvotes: 0

Views: 4257

Answers (1)

thelost
thelost

Reputation: 6694

Iterate over the group box components and check which ones are check boxes. Afterwards, check their Checked state, or whatever you want to do.

C# example:

foreach (Control c in groupBox1.Controls)
{
    if (c is CheckBox && ((CheckBox)c).Checked)
    {
        // whatever
    }
}

VB.NET example :

For Each c As Control In groupBox1.Controls
    If TypeOf c Is CheckBox AndAlso DirectCast(c, CheckBox).Checked Then
        ' Whatever
    End If
Next

Upvotes: 2

Related Questions