C# - How To Add CheckBox Column To DataGridView In C#

c# datagridview checkbox column

C# - How To Add DataGridViewCheckBoxColumn To Datagridview Using C#

____________________________________________________

In This C# Code We Will See How To Add A Check Box Column To Datagridview 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_add_checkbox_to_datagridview : Form
    {
        public Csharp_add_checkbox_to_datagridview()
        {
            InitializeComponent();
        }

        private void Csharp_add_checkbox_to_datagridview_Load(object sender, EventArgs e)
        {
            // add some row to datagridview
            // true the checkBox Is checked
            // false the checkBox Is Not checked
            dataGridView1.Rows.Add(true);
            dataGridView1.Rows.Add(true);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(true);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(true);
            dataGridView1.Rows.Add(false);
            dataGridView1.Rows.Add(false);
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToAddRows = false;

            ///////////////////////////////////

            DataGridViewCheckBoxColumn CheckBoxColumn = new DataGridViewCheckBoxColumn();
            CheckBoxColumn.HeaderText = "Check Box Column";
            dataGridView2.Columns.Add(CheckBoxColumn);
            dataGridView2.Rows.Add(false);
            dataGridView2.Rows.Add(true);
            dataGridView2.Rows.Add(false);
            dataGridView2.Rows.Add(true);
            dataGridView2.Rows.Add(true);
            dataGridView2.Rows.Add(true);
            dataGridView2.Rows.Add(false);
            dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView2.AllowUserToAddRows = false;

        }
    }
}



OutPut :
C# DataGridView CheckBox Column
C# DataGridView CheckBox Column




Share this

Related Posts

Previous
Next Post »