C# - How To check And UnCheck All CheckBoxes In GroupBox Or In Form

C# - How To check And UnCheck All CheckBoxes In The GroupBox Or In The Form


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Project : Form
    {
        public Project()
        {
            InitializeComponent();
        }
 
        //button to check all checkbox in form
        private void checkF_Click(object sender, EventArgs e)
        {
            foreach (Control c in Controls)
            {
                if (c is CheckBox)
                {
                    CheckBox cb = (CheckBox)c;
                    if (cb.Checked == false)
                    {
                        cb.Checked = true;
                        checkF.Text = "UnCheck";
                    }
                    else
                    {
                        cb.Checked = false;
                        checkF.Text = "Check";
                    }
                }
            }
        }
 
       //button to check all checkbox in groupBox
        private void checkG_Click(object sender, EventArgs e)
        {
            foreach (Control c in groupBox1.Controls)
            {
                if (c is CheckBox)
                {
                    CheckBox cb = (CheckBox)c;
                    if (cb.Checked == false)
                    {
                        cb.Checked = true;
                        checkG.Text = "UnCheck";
                    }
                    else
                    {
                        cb.Checked = false;
                        checkG.Text = "Check";
                    }
                }
            }
        }
 
    }
}
/////////////////////  END
///////////OUTPUT:

check all checkbox in groupBox and in form




Share this

Related Posts

1 comments:

comments

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer