Hi @Farshad Valizade , Welcome to Microsoft Q&A,
Your idea is perfectly viable, just create a custom DataGridView with this method.
Similar code is as follows:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace _11_15_x
{
public partial class Customdata : DataGridView
{
protected CheckBox headerCheckBox = new CheckBox();
public Customdata()
{
InitializeComponent();
// Your existing code for initializing the DataGridView
// Place the Header CheckBox bellows the bottom-right corner of the DataGridView Header.
headerCheckBox.Location = new Point(this.Width - 18, this.Height - 18);
headerCheckBox.BackColor = Color.Transparent;
headerCheckBox.Size = new Size(18, 18);
// Assign Click event to the Header CheckBox.
headerCheckBox.Click += new EventHandler(HeaderCheckBox_Clicked);
this.Controls.Add(headerCheckBox);
// Add a CheckBox Column to the DataGridView at the first position.
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
checkBoxColumn.FalseValue = 0;
checkBoxColumn.TrueValue = 1;
if (!this.Columns.Contains("checkBoxColumn"))
this.Columns.Insert(0, checkBoxColumn);
// Assign Click event to the DataGridView Cell.
this.CellContentClick += new DataGridViewCellEventHandler(DataGridView_CellClick);
}
protected void HeaderCheckBox_Clicked(object sender, EventArgs e)
{
// Your existing code for handling header checkbox click
}
protected void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
// Your existing code for handling cell click
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.