C# - How To Know If DataGridViewCheckBoxCell Is Checked In C#

c# datagridview checkbox is checked

C# Tutorial - How To Check If DataGridView CheckBox Is Checked Using C#

_____________________________________________________________

In This C# Code We Will See How To Check If DataGridView CheckBox Cell Is Checked Or Not In CSharp Programming Language .



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.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_DataGridView_CheckBoxCell_Checked : Form
    {
        public Csharp_DataGridView_CheckBoxCell_Checked()
        {
            InitializeComponent();
        }

        private void Csharp_DataGridView_CheckBoxCell_Checked_Load(object sender, EventArgs e)
        {
            // create datagridview checkbox column
            // add the column to the datagridview
            // add some row to the datagridview
            DataGridViewCheckBoxColumn CheckBoxColumn = new DataGridViewCheckBoxColumn();
            CheckBoxColumn.HeaderText = "Check Box Column";
            dataGridView1.Columns.Add(CheckBoxColumn);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToAddRows = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for(int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                bool isCellChecked = (bool)dataGridView1.Rows[i].Cells[0].Value;
                if(isCellChecked == true)
                {
                    MessageBox.Show("Is Checked");
                }
                else
                {
                    MessageBox.Show("Is Not Chiked");
                }
            }
        }
    }
}

OutPut:
c# datagridview checkbox column
c# datagridview checkbox checked and not checked




Share this

Related Posts

Previous
Next Post »

1 comments:

comments