How to get Selected Checkbox value in Visual basic, In this Vb tutorial, let’s create a simple VB application with a check box and display the selected checkbox value.
Get selected check box value in VB .NET
Check Box control is a control that allows the user to select or deselect options from the available options. When a check box is selected, a tick or checkmark will appear on the Windows form.
A Check Box control allows users to select single or multiple items from a list of items. It is used to get multiple inputs from the user or we can say it allows the user to select multiple choices from the set/group of choices.
And it takes user input in yes or no. To use Check Box we can drag it from the toolbox in visual studio.
Let’s create a Check Box control in VB.NET Windows form using the steps.
Step 1:
Open your visual studio click on the new project from the File menu, In visual select vb language, name the project, and then take one form into it. We have to drag the Check Box control from the toolbox and drop it into the Windows form.
Step 2:
when the Check Box is added to the form, we can set various properties of the check box.
Check Box Properties
These are some properties of the VB.NET Check Box control.
- Default: This property is used to get the default size of the check box.
- Auto Check: This property is used to check the checked value of the control can be automatically changed when the user clicked on the Check Box control.
- Check Align: This property is used to set the check Mark’s alignment, like horizontal or vertical on the check box.
- Appearance: This property is used to display the appearance of a check box control after setting a value.
- Check State: This property is used to verify whether the check box status is checked in the window form or not.
Step 3:
Then double click on the form and write the code on the coding part of a form to try the check box property.
Public Class Checkbxvb Private Sub Checkbxvb_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Text = "Colour selection" ' Set the title name of the form Label1.Text = "Select the Colours name" CheckBox1.Text = "Black" CheckBox2.Text = "Blue" CheckBox3.Text = "Red" CheckBox4.Text = "Orange" CheckBox5.Text = "Green" CheckBox6.Text = "Purple" Button1.Text = "Close" Button2.Text = "Submit" End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim colour As String colour = " " If CheckBox1.Checked = True Then colour = "Black" End If If CheckBox2.Checked = True Then 'colour = CheckBox2.Text colour = colour & " Blue" End If If CheckBox3.Checked = True Then colour = colour & " Red" End If If CheckBox4.Checked = True Then colour = colour & " Orange" End If If CheckBox5.Checked = True Then colour = colour & " Green" End If If CheckBox6.Checked = True Then colour = colour & " Purple" End If If colour.Length <> 0 Then MsgBox(" Selected items " & colour) End If CheckBox1.ThreeState = True End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click End 'terminate the program End Sub End Class
Output:
This is the design of our form. Now First of all run the application.
Then try to click on the checkboxes which you want to select. Then click on submit button.
When you click on submit button then the msg windows will pop up on the screen which shows all the selected check box values.
So In this way, you can get the all selected values of Check Box control in VB.NET.