Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Adding check box in checkboxlist control on run time using .net 2.0.

Author: Zunnair
Download Source Code : 810_checkboxlist.zip

In this simple article you will learn that how to add check box in checkboxlist control.

 create new c# project. Drag one checkboxlist control, one textbox and one button.

Now write following code on form load event:

 

 

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "Devasp checkBoxList App";

            textBox1.Text = "DevAsp.net";

 

            checkedListBox1.Items.Add("CheckBox1 On Load");

            checkedListBox1.Items.Add("CheckBox2 On Load");

            checkedListBox1.Items.Add("CheckBox3 On Load");

            checkedListBox1.Items.Add("CheckBox4 On Load");

            checkedListBox1.Items.Add("CheckBox5 On Load");

            checkedListBox1.Items.Add("CheckBox6 On Load");

           

        }

 

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "Devasp checkBoxList App"

        textBox1.Text = "DevAsp.net"

 

        checkedListBox1.Items.Add("CheckBox1 On Load")

        checkedListBox1.Items.Add("CheckBox2 On Load")

        checkedListBox1.Items.Add("CheckBox3 On Load")

        checkedListBox1.Items.Add("CheckBox4 On Load")

        checkedListBox1.Items.Add("CheckBox5 On Load")

        checkedListBox1.Items.Add("CheckBox6 On Load")

 

    End Sub

 

Now write following code on button click event

 

C#

private void button1_Click(object sender, EventArgs e)

        {

            try

            {

                if (textBox1.Text != string.Empty)

                    checkedListBox1.Items.Add(textBox1.Text);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

 

VB

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try

            If textBox1.Text <> String.Empty Then

                checkedListBox1.Items.Add(textBox1.Text)

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

 

This is the simple code for adding check boxes in checkboxlist control.

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Inheritance feature while working with forms in C# using .Net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net